Page 4 of 4

UVA problem no. 414

Posted: Thu Jul 17, 2014 5:17 pm
by richatibrewal
Code Accepted

Re: UVA problem no. 414

Posted: Thu Jul 17, 2014 8:24 pm
by brianfry713
Change your input parsing, don't forget about newline chars at the end of a line.
On this line:
scanf("%c",&a);
The first thing it reads is the newline char after N.

Re: UVA problem no. 414

Posted: Sat Jul 19, 2014 12:11 pm
by lighted
As BrianFry pointed change input parsing.

You can do it like this. Add this line to read newline char at the end.

Code: Select all

while (getchar() != '\n');
It must be

Code: Select all

while(scanf("%d",&s)!=EOF)
{
if(s==0)
break;
while (getchar() != '\n');
min=INT_MAX;
However this change doesn't lead to accepted. :-?
Very strange things with scanf and getchar.

When i changed scanf to getchar it got WA again.

Code: Select all

for(n=0;n<s;n++)
{
e=0;
for(i=0;i<25;i++)
{
a[i] = getchar();
if(a[i]==' ')
e++;
}
When i changed it to gets it got accepted. :) :-?

Code: Select all

for(n=0;n<s;n++)
{
e=0;
gets(a);
for(i=0;i<25;i++)
{
if(a[i]==' ')
e++;
}
I can't understand what's the difference between above 3 variants of code. :-?

Re: UVA problem no. 414

Posted: Tue Jul 22, 2014 11:26 pm
by brianfry713
lighted, you need to read the newline char at the end of every line.

Re: UVA problem no. 414

Posted: Tue Jul 22, 2014 11:38 pm
by lighted
Ok, i got it. I forget it. Thanks. :)