333 - Recognizing Good ISBNs
Moderator: Board moderators
Try to implement this in your program:
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').
If you still get wrong answer then i will give you some inputs.
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').
If you still get wrong answer then i will give you some inputs.
Here more test case:
input:
output:
Good luck ![:wink:](./images/smilies/icon_wink.gif)
input:
Code: Select all
This just for test.
0-1000-99999
0-123-4567-89
0-123-4567-890
1-111-111-111
Code: Select all
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.
![:wink:](./images/smilies/icon_wink.gif)
-
- New poster
- Posts: 7
- Joined: Wed Jun 05, 2002 3:27 pm
- Location: Portugal
- Contact:
-
- New poster
- Posts: 7
- Joined: Wed Jun 05, 2002 3:27 pm
- Location: Portugal
- Contact:
-
- New poster
- Posts: 44
- Joined: Wed Aug 14, 2002 3:02 am
333-Always WA
I have passed all test case in previous post, but I still got WA, what wrong with my code??
[c]
#include<stdio.h>
#include<string.h>
main()
{
char temp[81],ISBN[81],digit[81];
int s1[20],s2[20];
int correct,count,i,j;
#ifndef ONLINE_JUDGE
freopen("333.in","r",stdin);
freopen("333.out","w",stdout);
#endif
while(gets(temp))
{
if(strlen(temp)==0) { printf("is incorrect\n"); continue; }
correct=0;
i=0;
while(temp==' ') i++;
for(j=0;temp!='\0';i++,j++)
ISBN[j]=temp;
ISBN[j]='\0';
j--;
while(ISBN[j]==' ') j--;
ISBN[++j]='\0';
count=0;
for(i=0;ISBN!='\0';i++)
{
if(ISBN>='0' && ISBN<='9' || ISBN=='X')
{
digit[count]=ISBN;
count++;
}
}
/* check the correctness of 10 digit ISBN */
if(count==10)
{
for(i=0;i<9;i++)
if(ISBN=='X') goto cetak;
for(i=0;i<9;i++)
digit=digit[i]-'0';
if(digit[9]=='X') digit[9]=10;
else digit[9]=digit[9]-'0';
digit[10]='\0';
s1[0]=digit[0];
for(i=1;i<count;i++)
s1[i]=s1[i-1]+digit[i];
s2[0]=s1[0];
for(i=1;i<count;i++)
s2[i]=s2[i-1]+s1[i];
if(s2[count-1]%11==0) correct=1;
}
cetak:
if(correct==1) printf("%s is correct.\n",ISBN);
else printf("%s is incorrect\n",ISBN);
}
return 0;
}[/c]
[c]
#include<stdio.h>
#include<string.h>
main()
{
char temp[81],ISBN[81],digit[81];
int s1[20],s2[20];
int correct,count,i,j;
#ifndef ONLINE_JUDGE
freopen("333.in","r",stdin);
freopen("333.out","w",stdout);
#endif
while(gets(temp))
{
if(strlen(temp)==0) { printf("is incorrect\n"); continue; }
correct=0;
i=0;
while(temp==' ') i++;
for(j=0;temp!='\0';i++,j++)
ISBN[j]=temp;
ISBN[j]='\0';
j--;
while(ISBN[j]==' ') j--;
ISBN[++j]='\0';
count=0;
for(i=0;ISBN!='\0';i++)
{
if(ISBN>='0' && ISBN<='9' || ISBN=='X')
{
digit[count]=ISBN;
count++;
}
}
/* check the correctness of 10 digit ISBN */
if(count==10)
{
for(i=0;i<9;i++)
if(ISBN=='X') goto cetak;
for(i=0;i<9;i++)
digit=digit[i]-'0';
if(digit[9]=='X') digit[9]=10;
else digit[9]=digit[9]-'0';
digit[10]='\0';
s1[0]=digit[0];
for(i=1;i<count;i++)
s1[i]=s1[i-1]+digit[i];
s2[0]=s1[0];
for(i=1;i<count;i++)
s2[i]=s2[i-1]+s1[i];
if(s2[count-1]%11==0) correct=1;
}
cetak:
if(correct==1) printf("%s is correct.\n",ISBN);
else printf("%s is incorrect\n",ISBN);
}
return 0;
}[/c]
-
- New poster
- Posts: 44
- Joined: Wed Aug 14, 2002 3:02 am
-
- New poster
- Posts: 44
- Joined: Wed Aug 14, 2002 3:02 am
X is a valid character only if count=9, and your second mistake is if there are invalid ISBN you must print like this :
try this :
input :
output :
bye... ![:)](./images/smilies/icon_smile.gif)
Code: Select all
printf(" is incorrect.\n");
input :
Code: Select all
XX-0000000000-XX
XX000000XXX0000XXXXX
1234567890
Code: Select all
XX-0000000000-XX is correct.
XX000000XXX0000XXXXX is correct.
1234567890 is incorrect.
![:)](./images/smilies/icon_smile.gif)
-
- New poster
- Posts: 44
- Joined: Wed Aug 14, 2002 3:02 am
my program give output
isn't it true? or what the output should be?[/code]
Code: Select all
XX-0000000000-XX is incorrect.
XX000000XXX0000XXXXX is incorrect.
1234567890 is incorrect.