Page 5 of 7

Posted: Thu Oct 12, 2006 2:47 pm
by sunny
if u print a blank line u will get PE. u dont need 2 print anything if there is no lower/uppercase letter in the input.[/quote]

Posted: Fri Oct 13, 2006 10:49 am
by sklitzz
This is what I coded. And I keep getting WA. What did I forget?

Code: Select all

#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;

#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define SQ(x) (x)*(x)

string solve( string s ) {
 	int cnt[52]; memset( cnt, 0, sizeof( cnt ) );
	for( int i = 0; i < s.size(); ++i ) {
		if( s[i] >= 'a' && s[i] <= 'z' ) cnt[ s[i] - 'a' + 26 ]++;
		if( s[i] >= 'A' && s[i] <= 'Z' ) cnt[ s[i] - 'A' ]++;
	}
	
	int x = *(max_element( cnt, cnt + 52 ) );
	if( !x ) return "";	
	
	string ret = "";
	for( int i = 0; i < 26; ++i ) if( cnt[i] == x ) ret += (i + 'A');
	for( int i = 26; i < 52; ++i ) if( cnt[i] == x ) ret += (i + 'a' - 26);
	
	ret += " "; ret += ( x + '0' );
	
	return ret;	
}

int main() {
	string s;
	while( getline( cin, s ) ) {
		string o = solve( s );
		if( o.size() ) cout << o << endl;
	}
		
	return 0;
}

Posted: Wed Nov 29, 2006 4:47 am
by razor_blue
Does anyone know why my code is judged WA??
Give me critical I/O, please....

Code: Select all

REMOVED
Sorry, wrong thread....

Posted: Wed Nov 29, 2006 5:13 am
by Jan
I think you have posted in a wrong thread. The problem number should be 449.

499 - What's The Frequency, Kenneth?

Posted: Tue Sep 11, 2007 9:47 pm
by Jan
I submitted my accepted code and got WA. Can anybody verify this by submitting his/her code?

Thanks..

Posted: Wed Sep 12, 2007 3:57 am
by warenix
Hi Jan,

I've submitted my AC code, system responses "Solved".

Posted: Wed Sep 12, 2007 9:30 am
by Jan
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.

499-why TLE

Posted: Fri Jan 30, 2009 11:20 pm
by sazzadcsedu
I GOT TLE.
MY CODE

Code: Select all

  # include<stdio.h>

        int  main()

     {
        char ar[52]={'A','a','B','b','C','c','D','d','E','e','F','f','G','g',
        'H','h','I','i','J','j','K','k','L','l','M','m',
		'N','n','O','o','P','p','Q','q','R','r','S','s','T','t',
		'U','u','V','v','W','w','X','x','Y','y','Z','z'};
        int  count[52];
        char ch;
        int i;
        int max;
        char c;
       

        while(ch=getchar())

		{
          
			for(i=0;i<52;i++)
			{ 

            count[i]=0;
			}

        while(ch!='\n')
      {
         for(i=0;i<52;i++){
         
         if(ch==ar[i])  
         
         count[i]=count[i]+1;
    
      }
         ch=getchar();
   } 
   
   
                max=0;


    for(i=0;i<52;i++)
	 {   
             if(max<count[i])
		{
                     max=count[i];
                      c=ar[i];
	     }
    }

  

   
        for(i=0;i<52;i++)
    { 
               if(count[i]==max)
                  printf("%c",ar[i]);
  }  
       
			   printf(" %d\n",max);
		}

	   return 0;
		}   

Re: 499-why TLE

Posted: Wed Jun 17, 2009 8:38 pm
by moiseserg
check your while, compare to EOF

let's say: while((ch=getchar())!=EOF)

you can use a bigger array to avoid several comparations to increase speed

499Could you image the input datas to make my program wrong?

Posted: Wed Aug 18, 2010 4:40 am
by angrad
Here is my code for 494 Kindergarten Counting Game.I'd seen all the posts about the problem 494, but still I got WA after the judge.
Will The judge system give a test single 'a'? If so, how can I output? My answer is '1'.
So everyone who can tell me the key point, Thanx ! :D

Code: Select all

#include <stdio.h>

int main()
{
	char c;
	int count;
	int Is_Alph(char c);
	freopen("in.txt", "r", stdin);
	while((c=getchar())!=EOF)
	{
		count=0;
		while (c=='\n')
		{
			c=getchar();
		}
		while (c!='\n'&&c!=EOF)
		{
			if (Is_Alph(c))
			{
				count++;
			}
		    while((c=getchar())&&Is_Alph(c)&&c!='\n'&&c!=EOF);
		    if (c=='\n')
		    {
    			break;
    		}
			while((c=getchar())&&(!Is_Alph(c))&&c!='\n'&&c!=EOF);
		}
		printf("%d\n", count);
		if (c==EOF)
		{
			return 0;
		}
	}
	return 0;
}

int Is_Alph(char c)
{
	if (c>='A'&&c<='Z'||c>='a'&&c<='z')
	{
		return 1;
	}
	else
	{
		return 0;
	}	
}

Re: 499Could you image the input datas to make my program wr

Posted: Mon Mar 26, 2012 2:15 pm
by rlucca
Hi people,

Same problem. Can someone help me suggesting input to fix the program?

Thanks

Code: Select all

#include <stdio.h>
#include <math.h>
#include <string>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <algorithm> 
#include <vector>
#include <map>

using namespace std;


int main() {
    char ch;
    int major;
    int reads;
    map<char, int> chs;

    chs.clear();
    major = 0;
    reads = 0;

    while ( (ch = fgetc(stdin)) != EOF ) {
        if (ch == '\n') {
            if (major > 0) {
                map<char,int>::iterator it = chs.begin();
                for (;it != chs.end(); it++) {
                    if (it->second == major)
                        printf("%c", it->first);
                }
                printf(" %d\n", major);
            } else if (major == 0) {
                printf("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0\n");
            }

            chs.clear();
            major = 0;
            reads = -1;
        } else if (isalpha(ch) == true) {
            map<char,int>::iterator it = chs.find(ch);
            if (it == chs.end()) {
                chs[ch] = 1;
                if ( 1 > major ) major = 1;
            } else {
                it->second = it->second + 1;
                if ( it->second > major ) major = it->second;
            }
        }
        reads++;
    }

    if (reads > 0) {
            if (major > 0) {
                map<char,int>::iterator it = chs.begin();
                for (;it != chs.end(); it++) {
                    if (it->second == major)
                        printf("%c", it->first);
                }
                printf(" %d\n", major);
            } else if (major == 0) {
                printf("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0\n");
            }
    }

    return 0;
}
EDIT: To Accept, I only changed fgetc to scanf.

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

Posted: Thu Jun 28, 2012 1:11 pm
by PromeNabid
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

Re: 499-why TLE

Posted: Wed Jul 25, 2012 3:07 pm
by waleed.lutfi
AC :D

Thanks to Brianfry

Re: 499-why TLE

Posted: Wed Jul 25, 2012 11:40 pm
by brianfry713
Your code doesn't terminate properly, it gets stuck in an infinite loop.

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

Posted: Tue Aug 14, 2012 6:15 pm
by sophi
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;
}