333  Recognizing Good ISBNs
Moderator: Board moderators

 Guru
 Posts: 834
 Joined: Wed May 29, 2002 4:11 pm
 Location: Wroclaw, Poland
 Contact:
ungetc() is valid function for judges ... If I correct remember , I got Acc a few problems used this function
Best regards
DM
Best regards
DM
If you really want to get Accepted, try to think about possible, and after that  about impossible ... and you'll get, what you want ....
Born from ashes  restarting counter of problems (800+ solved problems)
Born from ashes  restarting counter of problems (800+ solved problems)

 New poster
 Posts: 39
 Joined: Wed Jan 22, 2003 11:02 am
I have these differences in output (y is my file, z is output above):
I believe mine is the more correct output, since an ISBN cannot start with 'X' .. and there cannot be spaces inside the ISBN number.
Also
Code: Select all
diff y z
1,2c1,2
< XX0000000000XX is incorrect. < y
< XX000000XXX0000XXXXX is incorrect.

> XX0000000000XX is correct. < z
> XX000000XXX0000XXXXX is correct.
20c20
< 089237 010 6 is incorrect. < y

> 089237 010 6 is correct. < z
Also
Code: Select all
AA0000000000AA is incorrect.
333  Always WA
Hi
I get WA just now. . But i have a confusion in output format.
If a input has starting and trailing space what is the output.
Plz sent me correct output of following input.
____
SMH
I get WA just now. . But i have a confusion in output format.
If a input has starting and trailing space what is the output.
Plz sent me correct output of following input.
\n => enter or new line0123456789X\n
0123456789X \n
0 1 2 345 6789X\n
XXX0123456789X\n
011223344556677889X\n
013162959X 013162959X\n
0abc13dfasdfa162959X\n
0 13162959X\n
XX000000XXX0000XXXXX\n
____
SMH
333 , i have some question to ask ..........................
pliz help me in getting ans to the following questions :
1) what if there is illegal character inside a ISBN . will it count as a valid ISBN ?????
example : 0abc13dfasdfa162959X
0 13162959X====> contains space inside the ISBN
2)what if there is an X in front of the ISBN .that means containing X in arbitary positions
rather than position 10 where it is counted as a valid character. will it count as a valid
ISBN ??????
XXXX0892370106 ====> is it correct ??????
3)what will happen if an ISBN contains more than 10 digits . some thing like this
08923701060892370106.though the first part of this is a valid ISBN(0892370106)
so will the complete line will be a valid ISBN(08923701060892370106).
My algorithm for this prob is quiet simple :
1) read the input .
2)if it is a blank line output :incorrect
3)if it is not a blank line , than remove the leading and trailing blanks .
4)parse the digit from the string in to an integer array and when it contains X at the 10
position it is okay .
5)than by array operation calculate S1(partial sum)
6)than by array operation calculate S2(partial sum)
7)check wheither (s2[last1] % 11 )==0
if yes output : correct
9)else output : incorrect
## i assumed no valid ISBN can contain illegal characters(space , tab , _ ,....) inside the
string.
## i also assumed X is only valid when it is on the 10 th position .in other case it is
counted as invalid
## when ever it contains more than 10 digit , i assumed it to be an invalid ISBN .
AM i right with my assumptions ?? pliz help me . i am getting Wa all the time .
i did not want to paste my clumpsy code here . if any one want to see my code . i can mail
him my code .
Bye
Riyad
1) what if there is illegal character inside a ISBN . will it count as a valid ISBN ?????
example : 0abc13dfasdfa162959X
0 13162959X====> contains space inside the ISBN
2)what if there is an X in front of the ISBN .that means containing X in arbitary positions
rather than position 10 where it is counted as a valid character. will it count as a valid
ISBN ??????
XXXX0892370106 ====> is it correct ??????
3)what will happen if an ISBN contains more than 10 digits . some thing like this
08923701060892370106.though the first part of this is a valid ISBN(0892370106)
so will the complete line will be a valid ISBN(08923701060892370106).
My algorithm for this prob is quiet simple :
1) read the input .
2)if it is a blank line output :incorrect
3)if it is not a blank line , than remove the leading and trailing blanks .
4)parse the digit from the string in to an integer array and when it contains X at the 10
position it is okay .
5)than by array operation calculate S1(partial sum)
6)than by array operation calculate S2(partial sum)
7)check wheither (s2[last1] % 11 )==0
if yes output : correct
9)else output : incorrect
## i assumed no valid ISBN can contain illegal characters(space , tab , _ ,....) inside the
string.
## i also assumed X is only valid when it is on the 10 th position .in other case it is
counted as invalid
## when ever it contains more than 10 digit , i assumed it to be an invalid ISBN .
AM i right with my assumptions ?? pliz help me . i am getting Wa all the time .
i did not want to paste my clumpsy code here . if any one want to see my code . i can mail
him my code .
Bye
Riyad
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN
some one help me to get 333 AC
i have tried all possible way to solve 333 . but after several submission i am continuously getting WA . i know the algorithm for this prob is not that complicated but for the difficult input set . so can any one help me in this , what i am missing and if have made any stupid mistake .
[cpp] [/cpp]
plizzzzzzzzzzz help me in this
Bye
Riyad
[cpp] [/cpp]
plizzzzzzzzzzz help me in this
Bye
Riyad
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN
hey for every body who is trying 333
the algorithm for the prob 333 as i mentioned before is not that complicated . but it has got a strict input set . i ll like to with draw this line >>>>>{{{{more over people tend to make it more complicated by saying their AC program has given an ISBN containing spaces in between as Correct ISBN}}}} . But as a matter of fact after getting AC i realized some thing about 333 which i am telling in this post .
some says inputs like
089237<space><space><space><space>0106 are right , there AC programs give the above input to be correct but my AC program give this input to be incorrect . as both of us r AC that means there is no such inputs containing spaces in between an isbn in the judge input data(But i am not that sure ) . But it definitely contains Empty lines as inputs . more over X is only valid when it is in the 10 th position of the isbn .
so the theme of my writing is after removing trailing and leading spaces and also inner Hypens the ISBN string should have the length of 10 . so no illegal character is allowed ............
i ll also love to with draw this line >>>>>>>>>so dont get distracted by different type of posts .Best Regards...
Bye
riyad
some says inputs like
089237<space><space><space><space>0106 are right , there AC programs give the above input to be correct but my AC program give this input to be incorrect . as both of us r AC that means there is no such inputs containing spaces in between an isbn in the judge input data(But i am not that sure ) . But it definitely contains Empty lines as inputs . more over X is only valid when it is in the 10 th position of the isbn .
so the theme of my writing is after removing trailing and leading spaces and also inner Hypens the ISBN string should have the length of 10 . so no illegal character is allowed ............
i ll also love to with draw this line >>>>>>>>>so dont get distracted by different type of posts .Best Regards...
Bye
riyad
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN

 New poster
 Posts: 21
 Joined: Sun Sep 14, 2003 11:44 pm
 Location: USA
 Contact:
333 Clarification
Hello All,
I've read in some of the posts that spaces between ISBN numbers ARE NOT tested but spaces before and after the ISBN are tested. I've read in some other posts that spaces between the ISBN number ARE tested and that spaces before and after then ISBN are also tested.
Could anyone clarify this for me????
My program does not check for spaces between the ISBN only after.
I get WA
[cpp]
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
int main(){
char *isbn;
isbn = new char[81];
int sum=0;
int partialsum=0;
int number_of_digits=0;
int num_of_errors=0;
while(cin >> isbn){
for(int i=0; i<strlen(isbn); i++){
if(isdigit(isbn)){
sum += (isbn  48);
partialsum += sum;
number_of_digits++;
/*
cout << "Sum: " << sum << endl;
cout << "Partial Sum: " << partialsum << endl;
cout << "Number of Digits: " << number_of_digits << endl;
*/
}
else if(isbn == 'X' && number_of_digits == 9){
sum += 10;
partialsum += sum;
number_of_digits++;
/*
cout << "Sum: " << sum << endl;
cout << "Partial Sum: " << partialsum << endl;
cout << "Number of Digits: " << number_of_digits << endl;
*/
}
if(!isdigit(isbn) && isbn != 'X' && isbn != '')
num_of_errors++;
}
if(number_of_digits == 10 && partialsum%11 == 0 && num_of_errors == 0)
cout << isbn << " is correct." << endl;
else{
cout << isbn << " is incorrect." << endl;
}
sum = 0;
partialsum=0;
number_of_digits=0;
num_of_errors=0;
delete [] isbn;
isbn = new char[81];
}
return 0;
}
[/cpp]
Appreciate the help!!!
Thanks ,
GCS
I've read in some of the posts that spaces between ISBN numbers ARE NOT tested but spaces before and after the ISBN are tested. I've read in some other posts that spaces between the ISBN number ARE tested and that spaces before and after then ISBN are also tested.
Could anyone clarify this for me????
My program does not check for spaces between the ISBN only after.
I get WA
[cpp]
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
int main(){
char *isbn;
isbn = new char[81];
int sum=0;
int partialsum=0;
int number_of_digits=0;
int num_of_errors=0;
while(cin >> isbn){
for(int i=0; i<strlen(isbn); i++){
if(isdigit(isbn)){
sum += (isbn  48);
partialsum += sum;
number_of_digits++;
/*
cout << "Sum: " << sum << endl;
cout << "Partial Sum: " << partialsum << endl;
cout << "Number of Digits: " << number_of_digits << endl;
*/
}
else if(isbn == 'X' && number_of_digits == 9){
sum += 10;
partialsum += sum;
number_of_digits++;
/*
cout << "Sum: " << sum << endl;
cout << "Partial Sum: " << partialsum << endl;
cout << "Number of Digits: " << number_of_digits << endl;
*/
}
if(!isdigit(isbn) && isbn != 'X' && isbn != '')
num_of_errors++;
}
if(number_of_digits == 10 && partialsum%11 == 0 && num_of_errors == 0)
cout << isbn << " is correct." << endl;
else{
cout << isbn << " is incorrect." << endl;
}
sum = 0;
partialsum=0;
number_of_digits=0;
num_of_errors=0;
delete [] isbn;
isbn = new char[81];
}
return 0;
}
[/cpp]
Appreciate the help!!!
Thanks ,
GCS
Thank you Little Joey
Just a small thank you to lil Joey for the immense help his sample input/output gave.
(After majjar fight I got AC)
(After majjar fight I got AC)
Just another brick in the wall...
333 ISBN numbers WA
Hi,
Can any one help me ? Why I am getting wrong answer ? Can any one give me some inputs/outputs or check my code where is the problem.
Code C:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
char str[100];
int i,counter,len,s1,s2;
void str_rev(char *s){
int i,j;
char temp;
len = strlen(str);
for(i=0,j=len1;i<j;i++,j){
temp=str;
str=str[j];
str[j]=temp;
}
}
void check(char *s){
int i;
str_rev(str);
for(i=len1;i>=0;i)
if(str!=32) break;
str[i+1]='\0';
str_rev(str);
}
int main()
{
while(gets(str)){
s1=s2=counter=0;
len=strlen(str);
check(str);
len=strlen(str);
for(i=0;i<len;i++){
if(isdigit(str)){s1+=str48;s2+=s1;counter++;}
else if(str=='X'){s1+=10;s2+=s1;counter++;}
}
if((s2%11) (counter!=10)) printf("%s is incorrect.\n",str);
else printf("%s is correct.\n",str);
str[100]='\0';
}
return 0;
}
Regards
Rony
Can any one help me ? Why I am getting wrong answer ? Can any one give me some inputs/outputs or check my code where is the problem.
Code C:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
char str[100];
int i,counter,len,s1,s2;
void str_rev(char *s){
int i,j;
char temp;
len = strlen(str);
for(i=0,j=len1;i<j;i++,j){
temp=str;
str=str[j];
str[j]=temp;
}
}
void check(char *s){
int i;
str_rev(str);
for(i=len1;i>=0;i)
if(str!=32) break;
str[i+1]='\0';
str_rev(str);
}
int main()
{
while(gets(str)){
s1=s2=counter=0;
len=strlen(str);
check(str);
len=strlen(str);
for(i=0;i<len;i++){
if(isdigit(str)){s1+=str48;s2+=s1;counter++;}
else if(str=='X'){s1+=10;s2+=s1;counter++;}
}
if((s2%11) (counter!=10)) printf("%s is incorrect.\n",str);
else printf("%s is correct.\n",str);
str[100]='\0';
}
return 0;
}
Regards
Rony
Testing your code with the following two examples:
The correct answer should be
While your program answers:
I.e. you have to treat tabs as whitespace also, and you also seems to have an issue with whitespaces embedded inside the ISBNnumbers.
Another thing, your code would be easier to understand if you use '\n' instead of 32 and so on...
Hope this helps you some!
/Hans
Code: Select all
<tab><space>0823025713
082<space>3025713
Code: Select all
0823025713 is correct.
082<space>3025713 is incorrect.
Code: Select all
<tab><space>0823025713 is correct.
082<space>3025713 is correct.
Another thing, your code would be easier to understand if you use '\n' instead of 32 and so on...
Hope this helps you some!
/Hans
333  Recognizing Good ISBNs
hi everyone,
I've already tryied all inputs and got the correct outputs suggested in the other 333's topic, but still got WA, here they are:
The outputs suggested and also generated by my code were:
May anyone who has already got this problem solved make sure this output is correct? And also suggest other extreme cases? 'Cause i dont know what else to do.
I've already tryied all inputs and got the correct outputs suggested in the other 333's topic, but still got WA, here they are:
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 correct.
XX000000XXX0000XXXXX is correct.
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.