Page 3 of 5
Posted: Thu Feb 10, 2005 5:12 pm
by misof
What compiler are you using?
I tried compiling your code on linux/g++, i get the following errors:
Code: Select all
a.cc:13: error: incompatible types in assignment of `int' to `int[50]'
a.cc:38: error: `strcmpi' undeclared (first use this function)
In other words,
probably wanted to be
Code: Select all
for (i=0;i<50;i++) space_cnt[i]=1;
For case-insensitive comparation, either include strings.h and use strcasecmp() or convert your string to lowercase before the comparision.
Posted: Fri Feb 11, 2005 5:44 am
by frankhuhu
Yeah,Got it! Thanks misof!AC now!

Posted: Wed Feb 16, 2005 8:34 pm
by ibrahim
for (i=0;i<50;i++) space_cnt=1;
Please correct this line. I see you declare space_cnt as array, but here you don't use any index.
Posted: Sun Feb 20, 2005 3:31 pm
by Lebedenco
Hi, A1. Thx for your support and sorry for the long delay. It's strange that this code i've posted compiles ok in my box... Anyway i got it AC after a closer look. (the mistake was around the "leading_blanks problem" - my input routine was just "eating" the blanks!

(I'll be removing my code from the last post.)
[]'s
Posted: Wed Jun 08, 2005 7:02 pm
by N|N0
This algorithm just omits nonalphabetical characters.
That means that "hello5how6are8you" becomes "hellohowareyou".
So there is only one big word instead of 3 words which could be in the dictionary.
A keyword ``occurs" in an excuse if and only if it exists in the string in contiguous form and is delimited by the beginning or end of the line or any non-alphabetic character or a space.
(Well, this topic is rather old, but for those of you who might have similar problem.)
Posted: Wed Jun 08, 2005 7:12 pm
by N|N0
And the p409.ps file is wrong too.
It shoud be:
All excuses can contain any upper or lower case alphanumeric character, a space, or any of the following punctuation marks [@#".,!?&] not including the square brackets and will not exceed 70 characters in length.
To consider.
Posted: Tue Aug 23, 2005 7:21 am
by _.B._
Greetings!
Besides the good observations already made, I found out that if you don't print the worst excuses (if > 1) in the order they appear in the input, you'll get a W.A.
The next statement is corrupted:
If there is more than one worst excuse, you may print them in any order.
Keep posting! 
409 WA I already test ...
Posted: Thu Oct 05, 2006 7:02 pm
by bigwaves
I saw other topics and tested with their entrances ,my program solved all of them , but I receive WA. What is wrong ?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
char aux[21];
int excuse_maior[2][20];
void limpa_aux()
{
for(int p=0;p<21;p++)
aux[p]='\0';
}
void zera_excuse_maior()
{
for(int z=0;z<20;z++)
{
excuse_maior[0][z]=0;
excuse_maior[1][z]=0;
}
}
main()
{
char key[20][21],excuse[20][71];
int key_n,excuse_n,tam_excuse,w=0,cont=0,exc_set=1,qtd_exc=0,pos_exc=0,maior=0;
zera_excuse_maior();
while(scanf("%d %d",&key_n,&excuse_n)==2)
{
qtd_exc=0;
pos_exc=0;
maior=0;
fflush(stdin);
for(int i=0;i<key_n;i++)
{
fflush(stdin);
gets(key);
}
for(int j=0;j<excuse_n;j++)
{
fflush(stdin);
gets(excuse[j]);
tam_excuse=strlen(excuse[j]);
cont=0;
for(int y=0;y<tam_excuse;y++)
if(isalpha(excuse[j][y]))
{
aux[w]=tolower(excuse[j][y]);
w++;
}
else
{
for(int u=0;u<key_n;u++)
if(strcmp(aux,key)==0)
cont++;
limpa_aux();
w=0;
}
for(int u=0;u<key_n;u++)
if(strcmp(aux,key)==0)
cont++;
limpa_aux();
w=0;
if(cont>=maior)
{
excuse_maior[0][pos_exc]=j;
excuse_maior[1][qtd_exc]=cont;
maior=cont;
qtd_exc++;
pos_exc++;
}
}
printf("Excuse Set #%d\n",exc_set);
for(int r=0;r<qtd_exc;r++)
if(excuse_maior[1][r]==maior)
printf("%s\n",excuse[excuse_maior[0][r]]);
exc_set++;
printf("\n");
}
}
Re: #409 got RTE
Posted: Fri Jul 10, 2009 5:32 pm
by Obaida
This Problem Gave me RTE 4 times!!!
But i can't figure it out...

any 1 plz help?
n thanks in advance..
Re: #409 some problems in this problem which can lead to WA
Posted: Fri Jul 10, 2009 8:50 pm
by mf
Most likely it's a buffer overflow. Text doesn't say that each word in excuses will be at most 20 characters (it could be up all 70 characters), but your program assumes that.
Why do you use so small arrays? Personally I'd just use the first round number, say 100, for all array sizes here, and it would work fine.
Also, scanf format is a bit wrong here: scanf("%d %d%", &m, &n). And if you want scanf() to read all characters up to the end of the line, and including \n character, just use: scanf("%d %d%*[^\n]%*c", &m, &n).
Re: #409 some problems in this problem which can lead to WA
Posted: Fri Jul 10, 2009 10:20 pm
by Obaida
Thank guru i got acc..
I think this line in the problem statement is wrong..
All excuses can contain any upper or lower case alphanumeric character, a space, or any of the following punctuation marks [SPMamp".,!?&] not including the square brackets and will not exceed 70 characters in length.
That's why i got RTE..
And i used scanf directly because..
I got this line for gets:-
Code: Select all
while(1){gets(key[i]);if(key[i][0]!=0)break;}
So i got acc without changing scanf.

Re: 409 - Excuses, Excuses
Posted: Sun Jun 13, 2010 1:24 am
by amishera
I had trouble getting it accepted. I did a funny thing. In stead of putting a newline character in between the outputs, I put it at the end of every output. And then it was accepted. It was funny because it could have shown presentation error instead of WA.
409 - Excuses, Excuses!
Posted: Sat Dec 22, 2012 6:13 pm
by aasun
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<cstdio>
#include<cctype>
using namespace std;
int main()
{
int test_key,test_line,a,i,j;
string st,line;
char arrey[100];
vector<string>store_key,key_test,result;
int p=0;
while(scanf("%d %d",&test_key,&test_line)!=EOF)
{
getchar();
p++;
for(i=1;i<=test_key;i++)
{
cin>>st;
store_key.push_back(st);
}
getchar();
int max=-1;
for(j=1;j<=test_line;j++)
{
a=0;
int num=0;
getline(cin,line);
for(i=0;i<line.size();i++)
{
if((line>=65 && line<=90)||(line>=97 && line<=122) )
{
if(line>=65 && line<=90) line=line+32;
arrey[a++]=line;
}
else
{
arrey[a++]='\0';
key_test.push_back(arrey);
a=0;
for(int q=0;q<store_key.size();q++)
if(store_key[q]==key_test[0]) num++;
key_test.clear();
}
if(i+1==line.size())
{
arrey[a++]='\0';
key_test.push_back(arrey);
a=0;
for(int q=0;q<store_key.size();q++)
if(store_key[q]==key_test[0]) num++;
key_test.clear();
}
}
if(num>max)
{
max=num;
result.clear();
result.push_back(line);
}
else if(num==max)
{
result.push_back(line);
}
}
cout<<"Excuse Set #"<<p<<endl;
for(int b=0;b<result.size();b++)
{
cout<<result<<endl;
}
result.clear();
store_key.clear();
cout<<endl;
}
return 0;
}
why i got WA in 409 (PLZ help)
Posted: Sat Dec 22, 2012 6:17 pm
by aasun
//I could not match the last \n
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<cstdio>
#include<cctype>
using namespace std;
int main()
{
int test_key,test_line,a,i,j;
string st,line;
char arrey[100];
vector<string>store_key,key_test,result;
int p=0;
while(scanf("%d %d",&test_key,&test_line)!=EOF)
{
getchar();
p++;
for(i=1;i<=test_key;i++)
{
cin>>st;
store_key.push_back(st);
}
getchar();
int max=-1;
for(j=1;j<=test_line;j++)
{
a=0;
int num=0;
getline(cin,line);
for(i=0;i<line.size();i++)
{
if((line>=65 && line<=90)||(line>=97 && line<=122) )
{
if(line>=65 && line<=90) line=line+32;
arrey[a++]=line;
}
else
{
arrey[a++]='\0';
key_test.push_back(arrey);
a=0;
for(int q=0;q<store_key.size();q++)
if(store_key[q]==key_test[0]) num++;
key_test.clear();
}
if(i+1==line.size())
{
arrey[a++]='\0';
key_test.push_back(arrey);
a=0;
for(int q=0;q<store_key.size();q++)
if(store_key[q]==key_test[0]) num++;
key_test.clear();
}
}
if(num>max)
{
max=num;
result.clear();
result.push_back(line);
}
else if(num==max)
{
result.push_back(line);
}
}
cout<<"Excuse Set #"<<p<<endl;
for(int b=0;b<result.size();b++)
{
cout<<result<<endl;
}
result.clear();
store_key.clear();
cout<<endl;
}
return 0;
}
Re: 409 - Excuses, Excuses!
Posted: Sat Dec 29, 2012 11:39 am
by brianfry713
don't double post.