本文介绍了总是使用C编程语言在uva 10008中获得WA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<stdio.h>
        #include<string.h>
        
        int main()
        {
            
        /* input the number of the line */
            int n;
            scanf("%d",&n);
            fflush(stdin); 
        
            /* build an array to compute the number of times that each alphabet appears */
            /* countt[0] stands for 'a' , countt[1] stands for' b' ,and so on... */
            int countt[26];
            int i;
            for(i=0;i<26;i++)
            {
                countt[i]=0;
            }
        
            /*build an array storing the alphabet*/
            char alpha[26];
            char u;
            int numal=0;
            for(u='A';numal<26;u++)
            {
                alpha[numal]=u;
                numal++;
            }
        
            /*build an array prepared to receive the input(string) */
            char mmm[1000][1000];
            int t,g;
        
            for(t=1;t<=n;t++)
            {
                scanf("%[^\n]",mmm[t]);
                fflush(stdin);
            }
        
            /* compute each alphabet appears in the all strings , and the number of times is documented in array"countt" */
            for(t=1;t<=n;t++)
            {
                for(g=0;mmm[t][g]!='\0';g++)
                {
                    if(mmm[t][g]>='a' && mmm[t][g]<='z')
                    {
                        countt[mmm[t][g]-'a']++;
                    }
        
                    if(mmm[t][g]>='A' && mmm[t][g]<='Z')
                    {
                        countt[mmm[t][g]-'A']++;
                    }
                }
            }
        
            /* sort the array"countt" in ascending order with selection sort */
            /* sort the array"alpha" according to the array"countt" */
            int swap,position;
            int o;
            char swap1;
            for(i=0;i<=24;i++)
            {
                for(o=i+1;o<=25;o++)
                {
                    position=i;
                    if(countt[i]<countt[o])
                        position=o;
                    if(position==o)
                    {
                        swap=countt[i];
                        countt[i]=countt[o];
                        countt[o]=swap;
        
                        swap1=alpha[i];
                        alpha[i]=alpha[o];
                        alpha[o]=swap1;
                    }
                }
            }
            
            /* if the number of time that alphabets appear in the strings is equal ,then order in dictionary form (G is front of I)*/
            
            char swap2;
            for(i=0;i<=24;i++)
            {
                for(o=i+1;o<=25;o++)
                {
                    if(countt[i]==countt[o])
                    {
                        if(alpha[i]>alpha[o])
                        {
                            swap2=alpha[i];
                            alpha[i]=alpha[o];
                            alpha[o]=swap2;
                        }
                    }
                }
            }
        
        
        /* display the result*/
            for(i=0;i<26;i++)
            {
                if(countt[i]!=0)
                {
                    printf("%c %d\n",alpha[i],countt[i]);
                }
            }
        
        
        
        
            return 0;
        }



以上是我的代码(回答UVa 10008)。

我总是得到结果,错误答案,但我使用调试功能(https://www.udebug.com/UVa/10008)检查我的答案,总是与接受的输出相同。



我没有想法是什么问题。

谢谢。



我尝试了什么:



我试图调试显示我的答案是正确的,但是当我提交给UVa时,我得到了WA。


Above is my code (answer to UVa 10008).
I always got the result,Wrong Answer,but I used the Debug Function(https://www.udebug.com/UVa/10008)to check my answer,always identical to the accepted output.

I have no idea what the problem is.
Thanks.

What I have tried:

I have tried to debug that display my answer is correct,but when I submitted to UVa ,I got WA.

推荐答案


这篇关于总是使用C编程语言在uva 10008中获得WA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 03:38