Page 3 of 7

Posted: Sat Aug 14, 2004 2:21 pm
by JaviGS
I think there is a \n after the last line
Regards
Javi

499 SOS

Posted: Sun Feb 20, 2005 11:52 pm
by ginie
Hi everybody!
I'm feed up of #499 as i can't make out what's wrong with my code - i get WA-. The only part i'm not sure about it is the way the program may end executing (ive tried with while(cin) and While(!feof(stdin)) ). Please help

#include <stdio.h>
#include <iostream.h>
#include <string.h>
void main()
{
int llista[52],sol[52],i,veg,repe,mi,ma,j,swap,min,k,lon;
char x[128],resp;

while (cin)
{
cin.getline(x,128,'\n');
lon=strlen(x);
for(k=0; k<52; k++)
llista[k]=llista[k]^llista[k];
for(k=0; k<lon; k++)
{
ma= ((int) x[k])-'A';mi= ((int) x[k])-'a';
if( (ma<26) && (ma >=0) ) llista[ma]++;
else if( (mi< 26) && (mi>=0) ) llista[mi+26]++;
}

veg=veg^veg; sol[0]=sol[0]^sol[0]; repe=repe^repe;
for( i=0; i<52; i++)
{
if( llista>veg ){ veg=llista; sol[0]=i; repe=repe^repe;}
else if( llista==veg ){ repe++; sol[repe]=i;}
}

for(i=0; i<=repe; i++)
{
min=sol;swap=i;
for(j=i+1; j<=repe; j++)
if(sol[j]<min) {min=sol[j];swap=j;}
sol[swap]=sol; sol=min;
}

if(lon==0)
{
cout<<"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0"<<endl;
}

else
{
for (i=0; i<=repe; i++)
{
if(sol>25) resp=(char)(sol-26+'a');
else resp=(char)(sol+'A');
cout<<resp;
}
cout<<" "<<veg<<endl;
}
}
}

Posted: Sat Feb 26, 2005 12:17 am
by Sedefcho

Code: Select all

The only part i'm not sure about it is the way the program may end executing (ive tried with while(cin) and While(!feof(stdin)) ). 
That's your BUG, nice guess.

Just two changes and you'll get ACC.

1) Read simply by using stdio.h.
Just do this :

Code: Select all

while (gets(x))  {
    /* YOUR CODE */ ; 
}
2) And as a subsequence of 1), of course you
should remove the first line in your while, which is :

Code: Select all

cin.getline(x,128,'\n');

Without these changes your program was giving WA
in the case when after the last line in INPUT there's
no NEWLINE character, but just directly an EOF.
Maybe it was giving WAs in other test cases too.

THANKS

Posted: Sat Feb 26, 2005 10:06 am
by ginie
THANKS A LOT, I'VE GET ACC :D :D :D
I'LL PAY MORE ATENTION ON THAT KIND OF ERRORS, IT'S JUST THAT IT UPSETS ME WA WHEN YOUR CODE IS CORRECT BUT UNABLE TO READ THE INPUT'S FORMAT

499 WA

Posted: Wed Apr 13, 2005 7:38 pm
by elmedin
please help

Code: Select all

#include <iostream>
#include <map>
#include <string>

using namespace std;
int main()
{
   string s;
   char hej;
   int i=0, k=0;
   char maj[1000];
   map<char, int> counter;
   while(getline(cin,s))
   {
      for(int l=0; l<s.length();l++)
      {  
         if(s[l]!=' ')     
         {
            hej=s[l];
            counter[hej]++;
         }
      }
      for(map<char, int>::const_iterator memo = counter.begin(); memo!=counter.end(); memo++)
      {
         if(memo->second > k)
         {
            i=0;
            k = memo -> second;
            maj[i]= memo->first;
         }
         else if(memo->second == k)
         {
            i++;
            maj[i]= memo->first;
         }
      }   
      for(int j=0; j<=i; j++)
      {
         cout<<maj[j];
      }
      cout<<" "<<k<<endl;
      k=0;
      counter.erase(counter.begin(), counter.end());
   }
   return 0;
}

About 499

Posted: Thu Jun 02, 2005 10:29 am
by Salman
why WA ????
SOME ONE PLEASE HELP!







Code: Select all


#include<stdio.h>
 
int main(){

     char  c;
     int my[52]={0},i,max;
     
        
        while(scanf("%c",&c)!=EOF){
         if(c!='\n'){
            if(c>=65 && c<=90){
                my[c-65]++;
            }    
            else if(c>=97 && c<=122){
                my[c-97+26]++;
            }    
            
            
         } 
         if(c=='\n'){
             max=0;
             for(i=0;i<26;i++){
                 if(my[i]>=my[i+26]){
                     my[i]+=my[i+26];
                     if(max<my[i]){
                         max=my[i];
                      }     
                     my[i+26]=0;
                 }    
                 else{
                     my[i+26]+=my[i];
                     if(max<my[i+26]){
                         max=my[i+26];
                     }    
                     my[i]=0;
                           
                 }    
             }  
   
             for(i=0;i<52;i++){
                 if(my[i]==max){
                    if(i<26){ 
                     printf("%c",i+65);
                    }
                    else{
                     printf("%c",i+97-26);   
                    }         
                 }                 
                 my[i]=0; 
             }    
             printf(" %d",max);
             printf("\n");
         }     //newline;  
  }    //while


      return 0;
}

Posted: Tue Jun 07, 2005 4:42 pm
by sahand
I replaced this part of your code

Code: Select all

 for(i=0;i<26;i++){
                 if(my[i]>=my[i+26]){
                     my[i]+=my[i+26];
                     if(max<my[i]){
                         max=my[i];
                      }     
                     my[i+26]=0;
                 }   
                 else{
                     my[i+26]+=my[i];
                     if(max<my[i+26]){
                         max=my[i+26];
                     }   
                     my[i]=0;
                           
                 }    
with:

Code: Select all

max=0;
			for(i=0;i<52;i++)			
				if(my[i]>max)
					max=my[i];			
And got AC.

Upper case letters are supposed to be different letters from their relative lower case ones.

499-PLS help

Posted: Sat Jun 25, 2005 8:57 pm
by 59557RC
i dont understantd why my code outputs somethin strange for inputin 1st samp in. for 1st time. but when 2nd time i input somethin it outputs correctly. some 1 pls explain me whats wrong ?

#include<stdio.h>

int main(void)
{

char a[200],str[200],max;
int i,j,k;

while(gets(str)!=NULL){
max=0;
for(i='a';i<='z';i++) a=0;
for(i='A';i<='Z';i++) a=0;

for(i=0;str!='\0';i++){
if(a[str]==0){
for(j=i;str[j]!='\0';j++) if(str==str[j]) a[str]++;
if(a[str]>max) max=a[str];
}
}
for(i='A';i<='Z';i++) if(a==max) printf("%c",i);

for(i='a';i<='z';i++) if(a==max) printf("%c",i);
printf (" %d",max);
printf("\n");
}
return 0;
}

Posted: Fri Jul 01, 2005 7:56 pm
by ronaldsaha
Before opening a new thread. pls look for what you are looking for.
visit this link bellow you will be benefited.

http://online-judge.uva.es/board/viewtopic.php?t=2712

for input

Code: Select all

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.
Hello                  Howard.
(this is a blank line)
-------( - are spaces only)
~!@#$%^&*()_+{}:"<>?`1234567890-=[];',./
my accepted code prints

Code: Select all

e 6
al 7
a 3
Hlo 2
Hlo 2
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
hope this will help you & like to hear you from soon that you got accepted.

Posted: Thu Sep 15, 2005 10:27 pm
by Jan
If there are are several letters that have the highest frequency u should print all of them alphabetically.
Did you consider this???

499 - Argggg, help pls

Posted: Fri Sep 16, 2005 6:13 am
by pajaskowiak
i tryed most of the inputs in other msgs and got WA :evil:

here is my code...

Code: Select all

#include <iostream.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>

int main() {
   int tamanho = 0;
   int i = 0;
   int aux1;
   char aux2;
   int j=0;   
   int maior=0;   
   char *linha = new char [4000];;
   char letras[300];
   int quantidade[300];
   int indice=0;
   strcpy(linha,"");
   bool teste = false;
   while (gets(linha)) {      
      for(i=0; i<300; i++) {
         quantidade[i] = 0;
      }
      tamanho = strlen(linha);            
      indice = 0;      
      maior = 0;          
      for (i=0; i<tamanho; i++) {         
         teste = false;
         for(j=0; j<indice; j++) {            
            if (linha[i] == letras[j]) {
               quantidade[j]++;
               teste = true;
            }
         }
         if (!teste) {
            if (isalpha(linha[i])!=0) {                  
               letras[indice] = linha[i];                  
               quantidade[indice] = 1;
               indice++;
            }
         }
      }      
      if (indice > 0) {     
         for(i=0; i<(indice-1); i++) {
            for(j=(indice-1); j>1; j--) {
               if (letras[j-1] > letras[j]) {
                  aux2 = letras[j-1];
                  aux1 = quantidade[j-1];
                  letras[j-1] = letras[j];
                  quantidade[j-1] = quantidade[j];
                  letras[j] = aux2;
                  quantidade[j] = aux1;
               }
            }
         }   
         for(i=0; i<indice; i++) {            
            if (quantidade[i]>quantidade[maior]) {
               maior = i;
            }
         }
         
         maior = quantidade[maior];
         
         for (i=0; i<indice; i++) {            
            if (quantidade[i] == maior) {
               cout<<letras[i];
            }
         }
         cout<<" "<<maior<<endl;
      }
      else {
         cout<<"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0 "<<endl;
      }      
   }      
   return 0;
}
can pls someone help me? i know its a silly problem, but i cant get AC =////

Posted: Tue Oct 04, 2005 9:45 pm
by n00i3
^^^ map is sorterd by default :)

hey man in your check you are using

Code: Select all

if(s[l]!=' ')
what about , . and other special characters? do an isChar check and try submitting your solution :) e.g

Code: Select all

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.
this, is, abso, lutely, crazy, dude.

Code: Select all

e 6
al 7
a 3
Hlo 2
, 5
you dont want that comma there now do you ;)

Posted: Wed Nov 09, 2005 11:12 pm
by Jan
The problem states
The list of letters should be an alphabetical list of upper case letters followed by an alphabetical list of lower case letters.
Input:

Code: Select all

bbaa
Output:

Code: Select all

ab 2
But your code returns...

Code: Select all

ba 2
Hope it works.

Posted: Thu Jan 05, 2006 12:05 pm
by =viki=
im getting wrong answer(but its working for the input given with the problem)

Code: Select all

#include<stdio.h>

int count[51];
void _initialize()
{
	int i;
	for(i=0;i<52;i++)
		count[i]=0;
}
int main(void)
{
	char ch,line[100];
	int i,j,max=0;

	while(1)
	{
		ch=getchar();
		if(ch>=65 && ch<=90)
		{
			count[ch-65]++;
		}
		if(ch>=97 && ch<=122)
		{
			count[ch-71]++;
		}
		if(ch=='\n')
		{
			for(j=0;j<52;j++)
			{
				if(max<count[j])
					max=count[j];
			}
			for(j=0;j<52;j++)
			{
				if(count[j]==max && j<=25)
				{
					printf("%c",j+65);
				}
				if(count[j]==max && j>25)
				{
					printf("%c",j+71);
				}
			}
			printf(" %d\n",max);
			max=0;
			_initialize();
		}
		if(ch=='.')
		{
			for(j=0;j<52;j++)
			{
				if(max<count[j])
					max=count[j];
			}
			for(j=0;j<52;j++)
			{
				if(count[j]==max && j<=25)
				{
					printf("%c",j+65);
				}
				if(count[j]==max && j>25)
				{
					printf("%c",j+71);
				}
			}
			printf(" %d\n",max);
			break;
		}
	}
	return 0;
}
plz help where am i wrong....

499 freq.. WA (getting output on my system though..)

Posted: Thu Jan 05, 2006 12:10 pm
by =viki=
help me plz...
for the inputs supplied with the problem it works dunno why im getting WA

Code: Select all

#include<stdio.h>

int count[51];
void _initialize()
{
	int i;
	for(i=0;i<52;i++)
		count[i]=0;
}
int main(void)
{
	char ch,line[100];
	int i,j,max=0;

	while(1)
	{
		ch=getchar();
		if(ch>=65 && ch<=90)
		{
			count[ch-65]++;
		}
		if(ch>=97 && ch<=122)
		{
			count[ch-71]++;
		}
		if(ch=='\n')
		{
			for(j=0;j<52;j++)
			{
				if(max<count[j])
					max=count[j];
			}
			for(j=0;j<52;j++)
			{
				if(count[j]==max && j<=25)
				{
					printf("%c",j+65);
				}
				if(count[j]==max && j>25)
				{
					printf("%c",j+71);
				}
			}
			printf(" %d\n",max);
			max=0;
			_initialize();
		}
		if(ch=='.')
		{
			for(j=0;j<52;j++)
			{
				if(max<count[j])
					max=count[j];
			}
			for(j=0;j<52;j++)
			{
				if(count[j]==max && j<=25)
				{
					printf("%c",j+65);
				}
				if(count[j]==max && j>25)
				{
					printf("%c",j+71);
				}
			}
			printf(" %d\n",max);
			break;
		}
	}
	return 0;
}
looks big but isnt that complicated....
im getting WA .. plz help...