333  Recognizing Good ISBNs
Moderator: Board moderators
Yes, a 'X' may only appear at the 10th position.
Very Strange, don't know what else may be wrong.
BUT:
Your program says:
0892370106 TEST is incorrect.
My program says:
0892370106 TEST is correct.
Although '0892370106 TEST' is obviously wrong. Seems that there are no such testcases.
In an other thread, someone said that you have to check tabs ('\t') at the beginning and at the end of a line, too. Do you check this? I hope that this is your mistake. I don't know if you really have to check it. Nevertheless, I do it.
Very Strange, don't know what else may be wrong.
BUT:
Your program says:
0892370106 TEST is incorrect.
My program says:
0892370106 TEST is correct.
Although '0892370106 TEST' is obviously wrong. Seems that there are no such testcases.
In an other thread, someone said that you have to check tabs ('\t') at the beginning and at the end of a line, too. Do you check this? I hope that this is your mistake. I don't know if you really have to check it. Nevertheless, I do it.

 New poster
 Posts: 33
 Joined: Tue Jun 29, 2004 1:38 pm
 Location: IITM,chennai,Tamil Nadu,India
 Contact:
333  PE  but why?
Here's my code that gives presentation error with oj.... is it because of the endl on seeing eof??
Code: Select all
#include<iostream>
#include<string>
#include<stdio.h>
#include<vector>
using namespace std;
#define line 80
int checkvalidcode(vector<int> digits, int lastdigitflag)
{
if(digits.size()==10 && lastdigitflag==0)
return 1;
else if(digits.size()==9 && lastdigitflag==1)
return 1;
else
return 0;
}
main()
{
char a[line];
while(cin.getline(a,line))
{
int n=strlen(a);
int lastdigitflag=0;
vector<int> digits;
for(int i=0;i<n;i++)
{
if(a[i]>=48 && a[i]<=57)
digits.push_back(a[i]'0');
}
if(a[n1]=='X')
{
lastdigitflag=1;
}
if(checkvalidcode(digits,lastdigitflag)==1)
{
int partialsum[10]={0};
int tempsum=0;
for(int i=0;i<digits.size();i++)
{
partialsum[i]=tempsum+digits[i];
tempsum=partialsum[i];
}
if(digits.size()==9)
partialsum[9]=tempsum+10;
int s2[10]={0};
tempsum=0;
for(int i=0;i<10;i++)
{
s2[i]=tempsum+partialsum[i];
tempsum=s2[i];
}
int i=0;
while(a[i]==' ')
{
i++;
}
for(int j=i;j<strlen(a);j++)
{
if(a[j]==''  (a[j]>=48 && a[j]<=97))
cout<<a[j];
}
if(s2[9]%11==0)
{
cout<<" is correct.\n";
}
else
{
cout<<" is incorrect.\n";
}
}
else
{
int i=0;
while(a[i]==' ')
{
i++;
}
for(int j=i;j<strlen(a);j++)
cout<<a[j];
cout<<" is incorrect.\n";
}
}
}
Karthe
Hi Jemerson,
You can find below your Test Input and the Correct Output
for that Input.
INPUT
OUTPUT
You can now just compare the outputs line by line, case by
case and debug your program in the test cases where our
programs produce different outputs.
Hope it helps.
You can find below your Test Input and the Correct Output
for that Input.
INPUT
Code: Select all
0810456877
0810456877432
This just for test.
0100099999
0123456789
01234567890
1111111111
0892370106
0892370106 TEST
XX0000000000XX
XX000000XXX0000XXXXX
1234567890
0823025713
013152447X
013152447x
082302571
08230257130
2803025713
07632200X1
0823025713
0823025713
0823025713
0823025713
0823025713
082 3025713
0823025 713
0823025713
082302_5713
013152447X bla
013A152447X
013152447X 
01315
2447X
0110
01434435
01 0111
OUTPUT
Code: Select all
0810456877 is correct.
0810456877432 is incorrect.
This just for test. is incorrect.
0100099999 is incorrect.
0123456789 is correct.
01234567890 is incorrect.
1111111111 is correct.
0892370106 is correct.
0892370106 TEST is incorrect.
XX0000000000XX is incorrect.
XX000000XXX0000XXXXX is incorrect.
1234567890 is incorrect.
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.
0823025713 is correct.
082302_5713 is incorrect.
013152447X bla is incorrect.
013A152447X is incorrect.
013152447X  is incorrect.
01315 is incorrect.
2447X is incorrect.
0110 is incorrect.
01434435 is incorrect.
01 0111 is incorrect.
case and debug your program in the test cases where our
programs produce different outputs.
Hope it helps.

 New poster
 Posts: 6
 Joined: Sat Jul 09, 2005 10:18 am
 Location: Daffodil International University,Dhaka
 Contact:
333 I got WA..anyone Help Me?
why i got WA.... plz help me
Code: Select all
int main() {
int s, s2, i, fail,j;
char str[81];
while (scanf("%s", str)==1) {
i = s = s2 = fail = j = 0;
while (str[j] && !fail) {
if (isdigit(str[j])) {
s += str[j]  '0';
s2 += s;
i++;
}
else if (str[j] == 'X') {
s += 10;
s2 += s;
i++;
}
else if (str[j] != '') {
fail = 1;
}
j++;
}
if (i != 10  s2%11) fail = 1;
printf("%s is %scorrect.\n", str, fail ? "in" : "");
}
return 0;
}
anis alamgir

 Experienced poster
 Posts: 106
 Joined: Thu Jan 29, 2004 12:07 pm
 Location: Bangladesh
 Contact:
hey, where did the headers go ?
Anyways, I have found your bug. Compare your output with my output. Hope this will help.
INPUT:
MY OUTPUT:
YOUR OUTPUR:
Anyways, I have found your bug. Compare your output with my output. Hope this will help.
INPUT:
Code: Select all
0892370106
0892370106
0892370106
0830636374
0060177586
This_is_garbage
1568840306
0823025713
0345313860
0671888587
0810456877
0671741195
0812520300
0345248651150
0452267404
0131390724
013152447X
XXXXXXXXXXX
0892370106
0892370106
0892350108
0892370106
0892370106
Code: Select all
0892370106 is correct.
0892370106 is correct.
0892370106 is correct.
0830636374 is correct.
0060177586 is correct.
This_is_garbage is incorrect.
1568840306 is correct.
0823025713 is correct.
0345313860 is correct.
0671888587 is correct.
0810456877 is correct.
0671741195 is correct.
0812520300 is correct.
0345248651150 is incorrect.
0452267404 is correct.
0131390724 is correct.
013152447X is correct.
XXXXXXXXXXX is incorrect.
0892370106 is correct.
0892370106 is correct.
0892350108 is incorrect.
0892370106 is correct.
is incorrect.
0892370106 is correct.
Code: Select all
0892370106 is correct.
0892370106 is correct.
0892370106 is correct.
0830636374 is correct.
0060177586 is correct.
This_is_garbage is incorrect.
1568840306 is correct.
0823025713 is correct.
0345313860 is correct.
0671888587 is correct.
0810456877 is correct.
0671741195 is correct.
0812520300 is correct.
0345248651150 is incorrect.
0452267404 is correct.
0131390724 is correct.
013152447X is correct.
XXXXXXXXXXX is incorrect.
0892370106 is correct.
0892370106 is correct.
0892350108 is incorrect.
0892370106 is correct.
0892370106 is correct.
Thanx for your help guys, finally i got it!
UFCG Brazil  Computer Science graduate student
http://acm.uva.es/problemset/usersnew.php?user=54806 ... and going up!
http://acm.uva.es/problemset/usersnew.php?user=54806 ... and going up!

 New poster
 Posts: 37
 Joined: Fri Apr 30, 2004 6:52 pm
 Location: Portugal
333  Inputs examples
I think I've the problem solved however OJ gives me RE so I'm guessing there must be some kind of input I haven't tested in my program and thus the crash. So I'd like to ask if anyone could give me some correct inputs and the correspondent outputs please.
I tested my program with this input:
And got this output:
Thanks
I tested my program with this input:
Code: Select all
0810456877
0810456877432
This just for test.
0100099999
0123456789
01234567890
1111111111
0892370106
0892370106 TEST
XX0000000000XX
XX000000XXX0000XXXXX
1234567890
0823025713
013152447X
013152447x
082302571
08230257130
2803025713
07632200X1
0823025713
0823025713
0823025713
0823025713
0823025713
082 3025713
0823025 713
0823025713
082302_5713
013152447X bla
013A152447X
013152447X 
01315
2447X
0110
01434435
01 0111
Code: Select all
0810456877 is correct.
0810456877432 is incorrect.
This just for test. is incorrect.
0100099999 is incorrect.
0123456789 is correct.
01234567890 is incorrect.
1111111111 is correct.
0892370106 is correct.
0892370106 TEST is incorrect.
XX0000000000XX is incorrect.
XX000000XXX0000XXXXX is incorrect.
1234567890 is incorrect.
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.
0823025713 is correct.
082302_5713 is incorrect.
013152447X bla is incorrect.
013A152447X is incorrect.
013152447X  is incorrect.
01315 is incorrect.
2447X is incorrect.
0110 is incorrect.
01434435 is incorrect.
01 0111 is incorrect.
My accepted code give
So there are differences. But you said you're getting RE. That's something else. Did you check other threads about this?
Code: Select all
0810456877 is correct.
0810456877432 is incorrect.
This just for test. is incorrect.
0100099999 is incorrect.
0123456789 is correct.
01234567890 is incorrect.
1111111111 is correct.
0892370106 is correct.
0892370106 TEST is incorrect.
XX0000000000XX is incorrect.
XX000000XXX0000XXXXX is incorrect.
1234567890 is incorrect.
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 correct.
0823025 713 is correct.
0823025713 is correct.
082302_5713 is correct.
013152447X bla is correct.
013A152447X is incorrect.
013152447X  is correct.
01315 is incorrect.
2447X is incorrect.
0110 is incorrect.
01434435 is incorrect.
01 0111 is incorrect.

 New poster
 Posts: 37
 Joined: Fri Apr 30, 2004 6:52 pm
 Location: Portugal
Thank you for your answer. I read somewhere that the spaces inside the isbn aren't tested so either correct or incorrect answer is ok but I thought _ inside isbn was incorrect.
MY output now is:
The difference is only this line: 0892370106 TEST is correct.
Yours give incorrect and I don't understand how can it be since you have 013152447X bla is correct. So what's the rule here? Is a string after an isbn code valid? Or is it another type of test?
Either way I still get RE :?
My code does the following:
1 Copies the input line to a string of 82 chars
2  Takes the leadings and trailings spaces
3  Test of input line has size 0, if so " " is incorrect
4  Else test if the isbn string is valid, if so gives the incorrect output
5  Calculation of s1(using the trimmed isbn string) and s2
6 Test if last s2 is divisable by 11 if so correct output else incorrect output
I checked every topic about this problem and can't find anything else that might help
MY output now is:
Code: Select all
0810456877 is correct.
0810456877432 is incorrect.
This just for test. is incorrect.
0100099999 is incorrect.
0123456789 is correct.
01234567890 is incorrect.
1111111111 is correct.
0892370106 is correct.
0892370106 TEST is correct.
XX0000000000XX is incorrect.
XX000000XXX0000XXXXX is incorrect.
1234567890 is incorrect.
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 correct.
0823025 713 is correct.
0823025713 is correct.
082302_5713 is correct.
013152447X bla is correct.
013A152447X is incorrect.
013152447X  is correct.
01315 is incorrect.
2447X is incorrect.
0110 is incorrect.
01434435 is incorrect.
01 0111 is incorrect.
Yours give incorrect and I don't understand how can it be since you have 013152447X bla is correct. So what's the rule here? Is a string after an isbn code valid? Or is it another type of test?
Either way I still get RE :?
My code does the following:
1 Copies the input line to a string of 82 chars
2  Takes the leadings and trailings spaces
3  Test of input line has size 0, if so " " is incorrect
4  Else test if the isbn string is valid, if so gives the incorrect output
5  Calculation of s1(using the trimmed isbn string) and s2
6 Test if last s2 is divisable by 11 if so correct output else incorrect output
I checked every topic about this problem and can't find anything else that might help

 New poster
 Posts: 37
 Joined: Fri Apr 30, 2004 6:52 pm
 Location: Portugal
Thanks again, I figured it would be something like that but I need some input that crashes since I can't find anything wrong with my code.
I took the trim function from a site and seems to be working ok, the rest of the functions I made only calculateS1 could give invalid reference if the string didn't have 10 digits in it but that's a pre condition that is met in my program. Did I miss something?
Thanks.
Code: Select all
program got AC and thus code edited
Thanks.
Last edited by Schutzstaffel on Tue Jan 03, 2006 9:47 pm, edited 1 time in total.
I've got your problem. I'll let you find where it is. Try this
There is no leading or trailing space!!!!!!!!!
If you still don't know where it is, let me know.
Code: Select all
0823025713
If you still don't know where it is, let me know.

 New poster
 Posts: 37
 Joined: Fri Apr 30, 2004 6:52 pm
 Location: Portugal