414 - Machined Surfaces
Moderator: Board moderators
-
- New poster
- Posts: 49
- Joined: Mon Jun 16, 2014 7:40 pm
UVA problem no. 414
Code Accepted
Last edited by richatibrewal on Sat Aug 23, 2014 4:23 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: UVA problem no. 414
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.
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!
Re: UVA problem no. 414
As BrianFry pointed change input parsing.
You can do it like this. Add this line to read newline char at the end.
It must be
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.
When i changed it to gets it got accepted.
I can't understand what's the difference between above 3 variants of code. 
You can do it like this. Add this line to read newline char at the end.
Code: Select all
while (getchar() != '\n');
Code: Select all
while(scanf("%d",&s)!=EOF)
{
if(s==0)
break;
while (getchar() != '\n');
min=INT_MAX;

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++;
}


Code: Select all
for(n=0;n<s;n++)
{
e=0;
gets(a);
for(i=0;i<25;i++)
{
if(a[i]==' ')
e++;
}

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