414 - Machined Surfaces

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

richatibrewal
New poster
Posts: 49
Joined: Mon Jun 16, 2014 7:40 pm

UVA problem no. 414

Post by richatibrewal »

Code Accepted
Last edited by richatibrewal on Sat Aug 23, 2014 4:23 pm, edited 1 time in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: UVA problem no. 414

Post 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.
Check input and AC output for thousands of problems on uDebug!
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: UVA problem no. 414

Post 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. :-?
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: UVA problem no. 414

Post by brianfry713 »

lighted, you need to read the newline char at the end of every line.
Check input and AC output for thousands of problems on uDebug!
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: UVA problem no. 414

Post by lighted »

Ok, i got it. I forget it. Thanks. :)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Post Reply

Return to “Volume 4 (400-499)”