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

User avatar
yahoo
Learning poster
Posts: 93
Joined: Tue Apr 23, 2002 9:55 am

Post by yahoo »

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.

kurnia w
New poster
Posts: 18
Joined: Fri Dec 06, 2002 3:53 pm
Location: Indonesia
Contact:

Post by kurnia w »

Try 3-4 times (with different tipe), still can't figure out what's the problem..last time WA 0.340
Aahh... :evil:, because of this problem i'm look's "more" stupid than before...he...he... :D

User avatar
yahoo
Learning poster
Posts: 93
Joined: Tue Apr 23, 2002 9:55 am

Post by yahoo »

No way.
:lol:
an ISBN has EXACTLY ten "digits" (including the checking character in the end). So check it carefully. :P

kurnia w
New poster
Posts: 18
Joined: Fri Dec 06, 2002 3:53 pm
Location: Indonesia
Contact:

Post by kurnia w »

Aaah... :lol: :lol: finally got PE (not bad),yahoo thank' a lot for the hint, especially the last one... :D

hank
Experienced poster
Posts: 146
Joined: Mon Feb 04, 2002 2:00 am
Location: VCORE.

Post by hank »

i always got wa.
can you give me some testdatas?
thanks a lot!

kurnia w
New poster
Posts: 18
Joined: Fri Dec 06, 2002 3:53 pm
Location: Indonesia
Contact:

Post by kurnia w »

Here more test case:

input:

Code: Select all

This   just    for test.
0-1000-99999
0-123-4567-89
0-123-4567-890
1-111-111-111
output:

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.
Good luck :wink:

Ivan Silva
New poster
Posts: 7
Joined: Wed Jun 05, 2002 3:27 pm
Location: Portugal
Contact:

Post by Ivan Silva »

I got all u'r test cases right, i check all cases talked in the board...

What should i print if a blank line comes in the input??

maybe if it wasnt to borring put some more input and output cases... maybe i'll find my error there.

Thx.
-Ivan

Ivan Silva
New poster
Posts: 7
Joined: Wed Jun 05, 2002 3:27 pm
Location: Portugal
Contact:

Post by Ivan Silva »

Ok i got it accepted!!!

The problem was those dam blank lines......
People deal with those blank like as if they were normal input, that will lead you to the right answer.

-Ivan

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

333-Always WA

Post by b3yours3lf »

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]

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

Post by UFP2161 »

Just taking a really quick glance, and the first thing that caught my eye is that blank lines (where you have strlen == 0) need output like so:
(space)is incorrect

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

Post by b3yours3lf »

I have already try (space)is incorrect by still got WA..

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

Post by UFP2161 »

Ah.. here's the problem:
0-89237-010-6
0-89237-010-6 TEST
0-89237-010-6 is correct.
0-89237-010-6 TEST is correct.

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

Post by b3yours3lf »

still WA...
[c]
correct=0;
for(i=0;ISBN!='\0';i++)
{
if(ISBN>='0' && ISBN<='9' || ISBN=='X')
{
digit[count]=ISBN;
count++;
}
else if(isalpha(ISBN)) goto cetak;
}
[/c][/c]

Hisoka
Experienced poster
Posts: 120
Joined: Wed Mar 05, 2003 10:40 am
Location: Indonesia

Post by Hisoka »

X is a valid character only if count=9, and your second mistake is if there are invalid ISBN you must print like this :

Code: Select all

printf(" is incorrect.\n");
try this :
input :

Code: Select all

XX-0000000000-XX
XX000000XXX0000XXXXX
1234567890
output :

Code: Select all

XX-0000000000-XX is correct.
XX000000XXX0000XXXXX is correct.
1234567890 is incorrect.
bye... :)

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

Post by b3yours3lf »

my program give output

Code: Select all

XX-0000000000-XX is incorrect.
XX000000XXX0000XXXXX is incorrect.
1234567890 is incorrect.
isn't it true? or what the output should be?[/code]

Post Reply

Return to “Volume 3 (300-399)”