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
Hisoka
Experienced poster
Posts: 120
Joined: Wed Mar 05, 2003 10:40 am
Location: Indonesia

Post by Hisoka »

Must be like mine. Try to solve it.

ISBN is a serial number ( 0123456789X ) in 10 digits. X is a valid ISBN if in 10th digit.

for example :
0-13-162959-X :
0 : valid character
- : invalid char
1 : valid char
3 : valid char
- : invalid char
.
.
.
X : valid char ( because in 10th digit ).

if ISBN is XX-0000000000-XX :
X : invalid char
X : invalid char
- : invalid char
0 : valid char
.
.
.
- : invalid char
X : invalid char ( because is not a 10th digit ISBN )
in this case 10th digit ISBN is 0

I'm sorry for my bad english, because of that, I cannot explain more than that to you.

GOOD LUCK. :)

Rav
New poster
Posts: 27
Joined: Sat Jun 14, 2003 1:00 pm
Location: Polska Wrocław

valid characters

Post by Rav »

could you tell me what character is valid.
if i good understand valid ISBN:
1) must have 10 digit or X
2) may contain hyphens( - ) somwhere like this --------------0-89237-010-6
do ( _ ) is hyphen too ?
3) may contain X somwhere (however hisoka spoke that only on 10th is this right ?)
4) end at \n or EOF
5) if any illegal character (letter,*,+,.,etc.) occur then ISBN is illegal (0-89237-010-6a)
please help and answer my questions.
Rafał Sokołowski

UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Re: valid characters

Post by UFP2161 »

1. Yes, an ISBN number can only contain '0' through '9' .. an 'X' .. and hyphens.
2. Hyphens may appear anywhere in the string. These can be simply ignored. A "_" is not considered a hyphen.
3. As the problem states, an 'X' can only occur in the 10th digit position.
4. Each line is new test case. End of input is denoted by EOF.
5. Correct, any thing that is not a digit, hyphen or 'X' makes the ISBN invalid.

little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey »

This must be the problem with the most board entries (apart from p100).
Let me try to summarise everything that has ever been discussed.

For this input (<S>=space, <T>=tab, <N>=newline, <EOF>=eof):

Code: Select all

0823025713<N>
013152447X<N>
013152447x<N>
<N>
082302571<N>
08230257130<N>
2803025713<N>
07632200X1<N>
<S>0823025713<N>
0823025713<S><N>
<T>0823025713<N>
0823025713<T><N>
<S><S><T><S>0823025713<T><T><S><N>	
082<S>3025713<N>
0823025<T>713<N>
--08-2----302--5713------<N>
082302_5713<N>
013152447X<S>bla<N>
013-A-152447X<N>
0-1-3-1-5-2-4-4-7-X-<S>-<N>
01315<N>
2447X<N>
<EOF>
My accepted program gives:

Code: Select all

0823025713<S>is<S>correct.<N>
013152447X<S>is<S>correct.<N>
013152447x<S>is<S>incorrect.<N>
<S>is<S>incorrect.<N>
082302571<S>is<S>incorrect.<N>
08230257130<S>is<S>incorrect.<N>
2803025713<S>is<S>incorrect.<N>
07632200X1<S>is<S>incorrect.<N>
0823025713<S>is<S>correct.<N>
0823025713<S>is<S>correct.<N>
0823025713<S>is<S>correct.<N>
0823025713<S>is<S>correct.<N>
0823025713<S>is<S>correct.<N>
082<S>3025713<S>is<S>incorrect.<N>
0823025<T>713<S>is<S>incorrect.<N>
--08-2----302--5713------<S>is<S>correct.<N>
082302_5713<S>is<S>incorrect.<N>
013152447X<S>bla<S>is<S>incorrect.<N>
013-A-152447X<S>is<S>incorrect.<N>
0-1-3-1-5-2-4-4-7-X-<S>-<S>is<S>incorrect.<N>
01315<S>is<S>incorrect.<N>
2447X<S>is<S>incorrect.<N>
<EOF>
I hope it clears the matter...

Rav
New poster
Posts: 27
Joined: Sat Jun 14, 2003 1:00 pm
Location: Polska Wroc&#322;aw

Post by Rav »

my prog gives answers for this input:
my prog dont show space in output

0823025713 is correct.
013152447X is correct.
013152447x is incorrect.
is incorrect.
082302571 is incorrect.
08230257130 is incorrect.
2803025713 is incorrect.
07632200X1 is incorrect.
0823025713 is correct.
0823025713 is correct.
0823025713 is correct.
0823025713 is correct.
0823025713 is correct.
0823025713 is correct. //this is not valid why ?
0823025713 is correct. //and this
--08-2----302--5713------ is correct.
082302_5713 is incorrect.
013152447Xbla is incorrect.
013-A-152447X is incorrect.
0-1-3-1-5-2-4-4-7-X-- is correct. //why it is incorrect
01315 is incorrect.
2447X is incorrect.

if someone wants help i can send my code just please tell
thanks for help
best regards
Rafał Sokołowski

UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 »

Code: Select all

082<S>3025713<S>is<S>incorrect.<N>
0823025<T>713<S>is<S>incorrect.<N>
0-1-3-1-5-2-4-4-7-X-<S>-<S>is<S>incorrect.<N>
These are all invalid because there are spaces/tabs inside the string. Only hyphens, digits, or an 'X' may appear inside the actual string (once trailing and leading whitespace is removed).

Rav
New poster
Posts: 27
Joined: Sat Jun 14, 2003 1:00 pm
Location: Polska Wroc&#322;aw

Post by Rav »

thanks for help it help my much but i'm disappointed beacuse i upgrade my code and get same output:
0823025713 is correct.
013152447X is correct.
013152447x is incorrect.
is incorrect.
082302571 is incorrect.
08230257130 is incorrect.
2803025713 is incorrect.
07632200X1 is incorrect.
0823025713 is correct.
0823025713 is correct.
0823025713 is correct.
0823025713 is correct.
0823025713 is correct.
082 3025713 is incorrect.
0823025 713 is incorrect.
--08-2----302--5713------ is correct.
082302_5713 is incorrect.
013152447X bla is incorrect.
013-A-152447X is incorrect.
0-1-3-1-5-2-4-4-7-X- - is incorrect.
01315 is incorrect.
2447X is incorrect.

then a was happy and send to OJ and immediately get CE. i send code here maybe someone could tells me where it is(there can be problem only in this lines who is selected beacuse my previous version don't contain this and get WA not CE):


i removed my code beacuse it was good (only small changes)
Last edited by Rav on Wed Aug 13, 2003 10:05 am, edited 2 times in total.
Rafał Sokołowski

oriol78
New poster
Posts: 32
Joined: Mon Mar 31, 2003 7:39 pm

never mind

Post by oriol78 »

never mind
Last edited by oriol78 on Tue Aug 12, 2003 4:24 pm, edited 1 time in total.

UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 »

You need to use something like
[cpp]getline (cin, input)[/cpp]
since each line is a potential ISBN number, and each line MAY contain whitespace within it. You would then also need to trim leading and trailing whitespace. Also, you need to check for invalid characters, which I don't think you do yet.

You should also read the recent posts about this problem:
http://online-judge.uva.es/board/viewtopic.php?t=3677

UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 »

If those were the only lines you added, it's more than likely that ungetc () (since that's the only new function, even though it is ANSI C 1989 in stdio.h) is not supported by the Judge, though I could be wrong .. You can always turn on the "send report to email" in your profile with the judge, so when you do get Compile Error, it'll tell you why.

oriol78
New poster
Posts: 32
Joined: Mon Mar 31, 2003 7:39 pm

thx !!!!

Post by oriol78 »

thx a lot, i don't think about whitespaces in the string

Rav
New poster
Posts: 27
Joined: Sat Jun 14, 2003 1:00 pm
Location: Polska Wroc&#322;aw

Post by Rav »

thanks all finally i got AC. CE was in function isdigit(c):
[cpp]if(isdigit(c))[/cpp] //c is char;
can someone tells me why there was problem ?

Best Regards
Rafał Sokołowski

b3yours3lf
New poster
Posts: 44
Joined: Wed Aug 14, 2002 3:02 am

Post by b3yours3lf »

at last I got accepted, thanks all, especially for Hisoka.
I have misunderstanding the problem and u help me to understand it.

SilVer DirectXer
New poster
Posts: 39
Joined: Wed Jan 22, 2003 11:02 am

Post by SilVer DirectXer »

my code is quie ugly, because i forced it to process the example appears here correctly.
However, i am still WA....please help
[cpp]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char s1[100];
char news1[100];
int temp[100];
int ps[100];
int i,j,k;
int counter,l;
int c,sum,cc,damn,act;
char anss[100];
void main(void)
{
while (1)
{
gets(s1);
if (feof(stdin))
exit(0);
l=strlen(s1);
for(i=0;i<=99;i++)
{
news1='\0';
temp=0;
ps=0;
anss='\0';
}
c=0;
sum=0;
cc=-1;
damn=0;
act=0;
for (i=0;i<l;i++)
{
if (s1!=' ' && s1!='\t')
{
news1[++cc]=s1;
}
if ((s1>='0' && s1<='9')|| s1=='X' || s1[i]=='-' || s1[i]==' ' || s1[i]=='\t')
{
if (s1[i]!='-' && s1[i]!=' ' && s1[i]!='\t' )
{
if (s1[i]!='X')
{
temp[++c]=s1[i]-0x30;
ps[c]=ps[c-1]+temp[c];
}
else
{
temp[++c]=10;
ps[c]=ps[c-1]+temp[c];
}
}

if (s1[i]==' '|| s1[i]=='\t')
{
if (c>=1 && c <=9)
damn=1;
if (c>=10)
act=1;
}
if (c>=10 && s1[i]=='-' && act==1)
damn=1;


}
else
damn=1;

}
if (damn==1)
goto expls;

if (c!=10)
{
for (i=0;i<=(int)strlen(s1);i++)
{
if (s1[i]!=' ' && s1[i]!='\t')
break;
}
strncpy(anss,&s1[i],strlen(s1)-i+1);
printf("%s",anss);
puts(" is incorrect");
continue;
}
j=0;
for (i=1;i<=9;i++)
{
if (temp[i]==10)
{
j=1;
break;
}
}
if (j==1)
{

for (i=0;i<=(int)strlen(s1);i++)
{
if (s1[i]!=' ' && s1[i]!='\t')
break;
}
strncpy(anss,&s1[i],strlen(s1)-i+1);
printf("%s",anss);
puts(" is incorrect");
continue;
}

for (i=1;i<=10;i++)
{
ps[i]+=ps[i-1];

}

if (ps[i] % 11 ==0)
{
printf("%s",news1);
puts(" is correct");
}
else
{

expls: for (i=0;i<=(int)strlen(s1);i++)
{
if (s1[i]!=' ' && s1[i]!='\t')
break;
}
strncpy(anss,&s1[i],((int)strlen(s1)-i+1));
printf("%s",anss);
puts(" is incorrect");
continue;
}
}
}











[/cpp]

b3yours3lf
New poster
Posts: 44
Joined: Wed Aug 14, 2002 3:02 am

Post by b3yours3lf »

Try this input :
XX-0000000000-XX
XX000000XXX0000XXXXX
1234567890
0-89237-010-6
0-89237-010-6 TEST
Hhehehe

This just for test.
0-1000-99999
0-123-4567-89
0-123-4567-890
1-111-111-111
I am a boy
0-8104-5687-7
0-8104-5687-7432
000-000-00X-2
0000000000
1111111111
0-89237-010-6
0-89237 -010 -6
0-8306-3637-4
0-06-017758-6
This_is_garbage
1-56884-030-6
0-8230-2571-3
0-345-31386-0
0-671-88858-7
0-8104-5687-7
0-671-74119-5
0-812-52030-0
0-345-24865-1-150
0-452-26740-4
0-13-139072-4
0-1315-2447-X
My accepted program give
XX-0000000000-XX is correct.
XX000000XXX0000XXXXX is correct.
1234567890 is incorrect.
0-89237-010-6 is correct.
0-89237-010-6 TEST is incorrect.
Hhehehe is incorrect.
is incorrect.
This just for test. is incorrect.
0-1000-99999 is incorrect.
0-123-4567-89 is correct.
0-123-4567-890 is incorrect.
1-111-111-111 is correct.
I am a boy is incorrect.
0-8104-5687-7 is correct.
0-8104-5687-7432 is incorrect.
000-000-00X-2 is incorrect.
0000000000 is correct.
1111111111 is correct.
0-89237-010-6 is correct.
0-89237 -010 -6 is correct.
0-8306-3637-4 is correct.
0-06-017758-6 is correct.
This_is_garbage is incorrect.
1-56884-030-6 is correct.
0-8230-2571-3 is correct.
0-345-31386-0 is correct.
0-671-88858-7 is correct.
0-8104-5687-7 is correct.
0-671-74119-5 is correct.
0-812-52030-0 is correct.
0-345-24865-1-150 is incorrect.
0-452-26740-4 is correct.
0-13-139072-4 is correct.
0-1315-2447-X is correct.
[/quote]

Post Reply

Return to “Volume 3 (300-399)”