ACM (UVa) : 11577


We can use gets () function to input string. But some times it is called that, gets () is a dangerous function, because of it’s omnivorous nature

there r many trivial solutions to resolve this.
U can use,
fflash (stdin);
in between scanf () and gets (), i.e,
scanf (“%d”, & Test_case);
fflash (stdin);
gets (string);

Another solution could be:
gets (string);
if (string [0] is equals to ”) then, gets (string); // means, take input again

Process:

Convert all upper case letters to lower
declare an array named like Alpha [26] = {0} // initially assign value 0

if u found an alphabet then increase value of respective element

means, if u found ‘a’ then, Alpha [1] ++
if ‘b’ then, Alpha [2]++
if ‘c’ then, Alpha [3]++
if ‘m’ then, Alpha [13]++
if ‘z’ then, Alpha [26]++

Now, find the maximum frequency of Alpha [26]
after that, those elements contain maximum frequency print that respective character.

Suppose, Alpha [5], Alpha [8], Alpha [11] and Alpha [15] contain equal and maximum frequency
then the output will be, ehko

Critical input:
1
aaAAbbBB ppaBAbP ..p. %Perekowpq

Critical output:
abp

Advertisements

One thought on “ACM (UVa) : 11577

  1. #include
    #include
    #include
    char a[202],b[202];
    int main()
    {

    int i,j,len,count,count1,k,r,x,t,n1,r1;
    char temp;
    while(scanf(“%d”,&n1)!=EOF)
    {
    getchar();
    for(x=0;x<n1;x++)
    {
    gets(a);
    count1=0;
    k=0;
    for (t = 0; a[t]; t++)
    a[t] = tolower(a[ t ]);
    len=strlen(a);

    for(i=0;i<len;i++)
    {
    count=1;
    if(a[i]=='0')
    continue;
    if(a[i]==' ')
    continue;
    if(a[i]!='0')
    {
    for(j=i+1;j=count1 && a[i]!=’0′)
    {
    count1=count;

    b[k++]=a[i];

    }
    }
    }
    for(r=0;r<k;r++)
    for(r1=0;r1b[r1+1])
    {
    temp=b[r1];
    b[r1]=b[r1+1];
    b[r1+1]=temp;
    }
    for(r=0;r<k;r++)
    {
    printf("%c",b[r]);
    }
    printf("\n");
    }
    }

    return 0;
    }
    what's probem of my code.plz mail me.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s