333 - Recognizing Good ISBNs

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

Moderator: Board moderators

Post Reply
ftomi
Learning poster
Posts: 64
Joined: Sun Jan 06, 2002 2:00 am
Location: Hungary
Contact:

Post by ftomi »

Should I accept the next ISBN?
"------963-19-0853-4-------"
What should I do, if the last line contain only EOF?
Is This 'empty' line "not correct", or is it the end of input?
Thanks!
..
A great helper
Posts: 454
Joined: Thu Oct 18, 2001 2:00 am
Location: Hong Kong

Post by .. »

Hi,

For most of the problem on online judge,
EOF is the end of input, and should NOT be processed........
Good luck~~
Ivan Golubev
Experienced poster
Posts: 167
Joined: Fri Oct 19, 2001 2:00 am
Location: Saint Petersburg, Russia

Post by Ivan Golubev »

------963-19-0853-4------- is correct.

Process blank line as other lines, i.e. output 'is incorrect' but EOF is always EOF, of course it need not to be handle.
ftomi
Learning poster
Posts: 64
Joined: Sun Jan 06, 2002 2:00 am
Location: Hungary
Contact:

Post by ftomi »

Thanks!
But in this case, what's wrong in my program?
:roll:
Ivan Golubev
Experienced poster
Posts: 167
Joined: Fri Oct 19, 2001 2:00 am
Location: Saint Petersburg, Russia

Post by Ivan Golubev »

It's difficult to say what's wrong. There were some tricks in this problem (AFAIR):

1. Hyphens can be anywere.
2. The ISBN cannot be less than 10 symbols long (of course, excluding hyphens) but can be more than 10 symbols.
3. There can be leading/trailing spaces and tabs.
4. There can be only one 'X' and it can be only at last position in the ISBN (so, there can be hyphens after 'X').
ftomi
Learning poster
Posts: 64
Joined: Sun Jan 06, 2002 2:00 am
Location: Hungary
Contact:

Post by ftomi »

Oh, I see!
I've just made it!
Hmm. Tab is space...
I notice it!
Thanks for all!
yatsen
Learning poster
Posts: 68
Joined: Fri Nov 23, 2001 2:00 am
Location: taiwan

Post by yatsen »

I thnik 333 is not difficult, but I got WA.
Can anyone tell me what is wrong with my code?
#include <stdio.h>
#include <string.h>
#include <ctype.h>
main()
{
int i,j,k,incorrect,isbn[3000],s1[3000],s2[3000];
char line[3000];
while (scanf("%s",line)==1)
{
incorrect=0;
for (i=0;i<3000;i++) isbn=0;
k=strlen(line);
for (i=0,j=0;i<k;i++)
{
if (line=='-') continue;
if (isdigit(line)) isbn[j++]=line-'0';
else
if (line=='X')
if (j==9) isbn[j++]=10;
else { incorrect=1; break; }
}
if (j!=10) incorrect=1;
else
{
s1[0]=isbn[0];
for (i=1;i<10;i++) s1=s1[i-1]+isbn;
s2[0]=s1[0];
for (i=1;i<10;i++) s2=s2[i-1]+s1;
if (s2[9]%11!=0) incorrect=1;
}

if (incorrect) printf("%s is incorrect.n",line);
else printf("%s is correct.n",line);
}
return 0;
}
ftomi
Learning poster
Posts: 64
Joined: Sun Jan 06, 2002 2:00 am
Location: Hungary
Contact:

Post by ftomi »

the next line wrong, beacause if there is gap between 2 part in line, your program handle it as 2 line.

while (scanf("%s",line)==1)

for example:
This is a wrong line

Your program generate 5 output line instead of 1.

You should use while(gets(line)) and search the start, and the end of the isbn in the line.
yatsen
Learning poster
Posts: 68
Joined: Fri Nov 23, 2001 2:00 am
Location: taiwan

Post by yatsen »

After use gets(s) instead of scanf("%s",s), I finally got accept!
Thank you very much!
C8H10N4O2
Experienced poster
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
Location: Pasadena, CA

Post by C8H10N4O2 »

Can someone tell me what is wrong with this code?
[cpp]
#include <cstdio>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>

using namespace std;

void main()
{
char B[1000],S[500];
bool GoodISBN;
int i,j;
vector<int> ISBN;
while(fgets(B,1000,stdin)!=NULL)
{
GoodISBN=true;
ISBN.clear();
for(i=0;i<strlen(B);i++)
{
if(!isdigit(B)
&&B!=' '
&&B!='-'
&&B!='X'
&&B!='\n'
&&B!='\t')
{
GoodISBN=false;
break;
}
if(isdigit(B))
{
ISBN.push_back(B-'0');
}
if(B=='X')
{
ISBN.push_back(10);
if(ISBN.size()!=10)
{
GoodISBN=false;
break;
}
}
}
if(GoodISBN)
{
if(ISBN.size()!=10)
{
GoodISBN=false;
}
j=0;
for(i=0;i<ISBN.size();i++)
{
j+=ISBN*(10-i);
}
if(j%11!=0)
{
GoodISBN=false;
}
}
strcpy(S,"");
sscanf(B,"%s",S);
if(GoodISBN)
{
printf("%s is correct.\n",S);
}
else
{
printf("%s is incorrect.\n",S);
}
}
}[/cpp]
wyvmak
Experienced poster
Posts: 110
Joined: Thu Dec 13, 2001 2:00 am

Post by wyvmak »

At least, as Ivan said, your code seems can accept more than one X - which is not allowed
C8H10N4O2
Experienced poster
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
Location: Pasadena, CA

Post by C8H10N4O2 »

Whenever it sees an 'X', it checks to make sure it is the 10th digit, otherwise it flags the ISBN as bad.
xenon
Learning poster
Posts: 100
Joined: Fri May 24, 2002 10:35 am
Location: Scheveningen, Holland

333 rejudgement??

Post by xenon »

So I woke up this morning, and found the Judge gave me one less problem solved than my own administration accounted for.
Checked, rechecked and double checked my mail, but no rejudgement notice.
Then compared all the problemnumbers in the Judge's solved-list against my own and discovered 333 was missing!
What is going on? Out of 3429 submissions, only ONE has AC. Can this really be true? And what about a rejudgement notice?

A very sad,
-xenon
Caesum
Experienced poster
Posts: 225
Joined: Fri May 03, 2002 12:14 am
Location: UK
Contact:

Post by Caesum »

I notice that rejudgement notices normally take a few days to arrive
xenon
Learning poster
Posts: 100
Joined: Fri May 24, 2002 10:35 am
Location: Scheveningen, Holland

Post by xenon »

Hmm.
Did you already dig deeper into the possible change? First inspection shows no change in the problem description. No warning sign with additional notes either, so I guess we're in the dark.
In a file I keep for making statistics, I found that some weeks ago there were some 600 people with AC on this problem. In my opinion it is a little harsh to sweep them all off by a rejudge, since that implicitly means they all misunderstood the problem :-?
But... such is life.

Still crying in the rain,
-xenon
Post Reply

Return to “Volume 3 (300-399)”