409 - Excuses, Excuses!

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

Moderator: Board moderators

misof
A great helper
Posts: 430
Joined: Wed Jun 09, 2004 1:31 pm

Post 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,

Code: Select all

for (i=0;i<50;i++) space_cnt=1;
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.
frankhuhu
New poster
Posts: 30
Joined: Tue Jul 20, 2004 5:22 am
Contact:

Post by frankhuhu »

Yeah,Got it! Thanks misof!AC now! :P
ibrahim
Experienced poster
Posts: 149
Joined: Mon Feb 07, 2005 10:28 pm
Location: Northern University, Bangladesh
Contact:

Post 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.
Lebedenco
New poster
Posts: 5
Joined: Mon Aug 23, 2004 6:55 am

Post 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
N|N0
New poster
Posts: 36
Joined: Tue Jan 25, 2005 10:33 pm
Location: Ljubljana, Slovenija
Contact:

Post 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.)
N|N0
New poster
Posts: 36
Joined: Tue Jan 25, 2005 10:33 pm
Location: Ljubljana, Slovenija
Contact:

Post 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.
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

To consider.

Post 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! :D
_.
bigwaves
New poster
Posts: 1
Joined: Thu Oct 05, 2006 6:10 pm

409 WA I already test ...

Post 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");
}
}
"... Then people will see the Son of the
Man (God) coming in a cloud, with power and great glory."(Lucas 21:25 to 29) - Try to receive Jesus while you can find Him.
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: #409 got RTE

Post by Obaida »

This Problem Gave me RTE 4 times!!!
But i can't figure it out... :( any 1 plz help?
n thanks in advance.. :)

Code: Select all

removed
Last edited by Obaida on Fri Jul 10, 2009 10:23 pm, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: #409 some problems in this problem which can lead to WA

Post 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).
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: #409 some problems in this problem which can lead to WA

Post 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. :)
try_try_try_try_&&&_try@try.com
This may be the address of success.
amishera
New poster
Posts: 38
Joined: Sat Dec 27, 2008 10:42 pm

Re: 409 - Excuses, Excuses

Post 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.
aasun
New poster
Posts: 2
Joined: Sat Dec 22, 2012 5:57 pm

409 - Excuses, Excuses!

Post 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;
}
aasun
New poster
Posts: 2
Joined: Sat Dec 22, 2012 5:57 pm

why i got WA in 409 (PLZ help)

Post 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;
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 409 - Excuses, Excuses!

Post by brianfry713 »

don't double post.
Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “Volume 4 (400-499)”