499 - What's The Frequency, Kenneth?

All about problems in Volume IV. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

499 - What's The Frequency, Kenneth?

Postby Jan » Tue Sep 11, 2007 9:47 pm

I submitted my accepted code and got WA. Can anybody verify this by submitting his/her code?

Thanks..
Ami ekhono shopno dekhi...
HomePage
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

Postby warenix » Wed Sep 12, 2007 3:57 am

Hi Jan,

I've submitted my AC code, system responses "Solved".
User avatar
warenix
New poster
 
Posts: 5
Joined: Sun Aug 12, 2007 1:17 pm

Postby Jan » Wed Sep 12, 2007 9:30 am

Well, the problem is that, I got accepted by ignoring blank lines. But the output should be ' 0' as the problem specified. So, the judge input file shouldn't contain blank lines.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

Re: 499 - What's The Frequency, Kenneth?

Postby PromeNabid » Thu Jun 28, 2012 1:11 pm

Some sample I/Os, this might help.
Sample Input:
Code: Select all
#include <stdio.h>

main()
{
  int i;
  char *suffix[]= { "st", "nd", "rd" };
  char *item[]= { "Unix" , "cat", "sed", "awk", "grep", "ed", "vi"};
 
  printf("In the beginning, there was nothing.\n");
  for (i= 0; i < 7; i++)
    printf("And on the %d%s day, God created %s. And it was good.\n",
           i + 1, (i < 3) ? suffix[i] : "th", item[i]);
}

But then God saw that vi led people into temptation. Instead of choosing the righteous ways of make, dbx, and RCS, people used long command lines, printf(), and tape backups.

So God decreed, ``I see that Engineers have thus defiled my vi. And so, I shall create emacs, an editor more powerful than words. Further, for each instantiation vi hitherto, the Engineer responsible shalt perform Penance. And lo, the Penance wilt be painful; there will be much wailing and gnushingof teeth. The Engineer will read many lines of text. For each line of text, the Engineer must tell me which letters occur the most frequently.''

``I charge you all with My Golden Rule: 'Friends shalt not let friends use vi'.''

Input and Output

Each line of output should contain a list of letters that all occured with the highest frequency in the corresponding input line, followed by the frequency.

The list of letters should be an alphabetical list of upper case letters followed by an alphabetical list of lower case letters.

Sample Input

When riding your bicycle backwards down a one-way street, if the
wheel falls of a canoe, how many ball bearings does it take to fill
up a water buffalo?
Hello Howard.

Sample Output:
Code: Select all
di 2
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
aimn 1
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
i 2
dfrs 2
e 4
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
n 8
i 3
d 7
i 6
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
e 14
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
e 55
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
e 7
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
tu 3
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
e 15
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
e 15
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
p 2
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
e 6
al 7
a 3
Hlo 2
PromeNabid
New poster
 
Posts: 13
Joined: Mon Jun 18, 2012 12:52 am
Location: Dhaka, Bangladesh.

Re: 499 - What's The Frequency, Kenneth?

Postby sophi » Tue Aug 14, 2012 6:15 pm

But what's the problem with my code.I got WA
Code: Select all
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>


int main()
{
    char str[500];
    int arr[52];
    int index,k,j;
   // freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    while(gets(str))
        {
            int length = strlen(str);
                if(length==0) continue;
            for(k=0;k<=52;k++) arr[k]=0;

            for(j=0;j<length;j++)
                {
                   char ch =str[j];

                   if(ch>=65 && ch <=90)
                    {

                        index =ch-65+26;
                        arr[index]+=1;

                    }

                    if(ch>=97 && ch<=122)
                        {
                            index = ch-97;
                            arr[index]++;
                        }
                }


                 int mi=0;
                 int i;
                 char c;

                for(i=0;i<52;i++)
                {
                    if(arr[mi] < arr[i])
                        {
                           mi=i;
                        }

                }


                        for(i=26;i<52;i++)
                        if(arr[mi]==arr[i])
                            {

                                c=65+i-26;
                                printf("%c",c);


                           }


                            for(i=0;i<26;i++)
                            if(arr[mi]==arr[i])
                            {
                                c=97+i;
                                printf("%c",c);

                            }

                printf(" %d\n",arr[mi]);
           }

    return 0;
}
sophi
New poster
 
Posts: 6
Joined: Tue Aug 14, 2012 6:00 pm

Re: 499 - What's The Frequency, Kenneth?

Postby brianfry713 » Tue Aug 14, 2012 11:29 pm

Doesn't match the sample I/O.
brianfry713
Guru
 
Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 499 - What's The Frequency, Kenneth?

Postby sophi » Wed Aug 15, 2012 10:41 am

I changed my while loop like that
Code: Select all
while(gets(str)!=NULL)

Now it matches the sample I/O But again WA
what's the problem now ?
sophi
New poster
 
Posts: 6
Joined: Tue Aug 14, 2012 6:00 pm

Re: 499 - What's The Frequency, Kenneth?

Postby brianfry713 » Wed Aug 15, 2012 11:05 pm

Doesn't match the sample I/O. Post your complete updated code.
brianfry713
Guru
 
Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 499 - What's The Frequency, Kenneth?

Postby sophi » Thu Aug 16, 2012 1:14 am

My Complete code is given here.My I/O matches with the I/O given by @ PromeNabid previously in this topic.
Code: Select all
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>


int main()
{
    char str[500],ch;
    int arr[52];
    int index,k,j;

   
      /*
         freopen("input.txt","r",stdin);
         freopen("output.txt","w",stdout);
      */

    while(gets(str)!=NULL)
        {
            int length = strlen(str);
            //if() continue;

            for(k=0;k<=52;k++) arr[k]=0;

            for(j=0;j<length;j++)
                {
                   ch =str[j];

                   if(ch>=65 && ch <=90)
                    {

                        index =ch-65+26;
                        arr[index]+=1;

                    }

                    if(ch>=97 && ch<=122)
                        {
                            index = ch-97;
                            arr[index]++;
                        }
                }
               

                 int mi=0;
                 int i;
                 char c;

                for(i=0;i<52;i++)
                {
                    if(arr[mi] < arr[i])
                        {
                           mi=i;
                        }

                }


                        for(i=26;i<52;i++)
                        if(arr[mi]==arr[i])
                            {

                                c=65+i-26;
                                printf("%c",c);


                           }


                            for(i=0;i<26;i++)
                            if(arr[mi]==arr[i])
                            {
                                c=97+i;
                                printf("%c",c);

                            }

                printf(" %d\n",arr[mi]);

        }
    return 0;
}
sophi
New poster
 
Posts: 6
Joined: Tue Aug 14, 2012 6:00 pm

Re: 499 - What's The Frequency, Kenneth?

Postby brianfry713 » Thu Aug 16, 2012 11:38 pm

On line 24 you clear arr[52], which is not part of an array declared as int arr[52]; (valid are arr[0] through arr[51]).
brianfry713
Guru
 
Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 499 - What's The Frequency, Kenneth?

Postby sophi » Tue Aug 21, 2012 11:17 pm

Thanks a lot @brianfry713 . I got AC :)
sophi
New poster
 
Posts: 6
Joined: Tue Aug 14, 2012 6:00 pm

Re: 499 - What's The Frequency, Kenneth?

Postby ma7modx » Wed Oct 31, 2012 5:06 pm

whats the problem with my code (WA) ?
Code: Select all
#include <iostream>
#include <string>
#include <utility>
#include <string.h>
#include <algorithm>
using namespace std ;
int main()
{
   string name ;
   while(getline(cin,name) && name.size() )
   {
      int max = 0 ;
      int table [100000] ;
      memset(table,0,sizeof(table));
      string out ;
      
      for(int x = 0 ; x < name.size() ; ++x)
      {
         table[ name[x] ] ++ ;

         if(table[ name[x] ] > max && ((name[x]>='a' && name[x]<='z')||(name[x]>='A' && name[x]<='Z')))
         {
            max = table[ name[x] ] ;
            out.erase(out.begin(),out.end());
            out+=name[x] ;
         }
         else if(table[ name[x] ] == max)
            out+=name[x] ;
      }
      sort(out.begin() , out.end());
      
   
         cout << out <<" "<< max <<endl ;


   }
   return 0 ;
}
ma7modx
New poster
 
Posts: 1
Joined: Wed Oct 31, 2012 2:54 am

Re: 499 - What's The Frequency, Kenneth?

Postby brianfry713 » Wed Oct 31, 2012 9:51 pm

Try input:
Code: Select all
A.
AC output:
Code: Select all
A 1
brianfry713
Guru
 
Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 499 - What's The Frequency, Kenneth?

Postby alimbubt » Fri Feb 15, 2013 7:11 pm

Some Critical Input that harassed me....
Input:
Code: Select all
,,alim..ALIM
@@alim0123alim%%alim...AALL
..alim222.. .. .. &&alim..AAFFGG
Bangladesh University of Business & Technology
(Alim)(Alim)(Alim)  aa
(Alim) (Alim)()

Output:
Code: Select all
AILMailm 1
alim 3
AFGailm 2
s 5
Alim 3
Alim 2
Give me six hours to chop down a tree and I will spend the first four sharpening the axe...(BUBT ILLUSION)
http://uhunt.felix-halim.net/id/155497
http://onlyprogramming.wordpress.com/
alimbubt
New poster
 
Posts: 39
Joined: Tue Aug 07, 2012 10:40 pm
Location: BUBT,Dhaka, Bangladesh


Return to Volume IV

Who is online

Users browsing this forum: Bing [Bot] and 1 guest