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.
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.
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.
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
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).
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.
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.
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.
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;
}
}
}
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.