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

Post Reply
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

ungetc() is valid function for judges ... If I correct remember , I got Acc a few problems used this function :)

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)
SilVer DirectXer
New poster
Posts: 39
Joined: Wed Jan 22, 2003 11:02 am

Post by SilVer DirectXer »

XX-0000000000-XX is correct???

why?

how about
AA-0000000000-AA?

oh, hard to identify if it is valid or not..
UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 »

I have these differences in output (y is my file, z is output above):

Code: Select all

diff y z
1,2c1,2
< XX-0000000000-XX is incorrect. <-- y
< XX000000XXX0000XXXXX is incorrect.
---
> XX-0000000000-XX is correct. <-- z
> XX000000XXX0000XXXXX is correct.
20c20
< 0-89237 -010 -6 is incorrect. <-- y
---
> 0-89237 -010 -6 is correct. <-- z
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

AA-0000000000-AA is incorrect.
FaisalBD
New poster
Posts: 3
Joined: Thu Nov 27, 2003 10:24 am
Location: Dhaka, Bangladesh

333 - Always WA

Post by FaisalBD »

Hi
I get WA just now. :cry: . 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.
0-1-2-3-4-5-6-7-8-9-X\n
0-1-2-3-4-5-6-7-8-9-X \n
0- 1- 2- 3-4-5 -6-7-8-9-X\n
XXX-0-1-2-3-4-5-6-7-8-9-X\n
0-11-22-33-44-55-66-77-88-9-X\n
0-13-162959-X 0-13-162959-X\n
0abc-13dfasdfa-162959-X\n
0 -13-162959-X\n
XX000000XXX0000XXXXX\n
\n => enter or new line
____
SMH
User avatar
Riyad
Experienced poster
Posts: 131
Joined: Thu Aug 14, 2003 10:23 pm
Location: BUET
Contact:

333 , i have some question to ask ..........................

Post by Riyad »

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 :- 0abc-13dfasdfa-162959-X
0 -13-162959-X====> 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 ??????
XXXX-0-89237-010-6 ====> is it correct ??????

3)what will happen if an ISBN contains more than 10 digits . some thing like this

0-89237-010-6-----0-89237-010-6.though the first part of this is a valid ISBN(0-89237-010-6)
so will the complete line will be a valid ISBN(0-89237-010-6-----0-89237-010-6).

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[last-1] % 11 )==0
8)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
deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm

Post by deddy one »

in my accepted solution

1. valid isbn may contain white space
2. it should be 10 digit ( X is counted as digit if there is any )
3. if there is any X it must be occurs once and in the tenth position
[/b]
User avatar
Riyad
Experienced poster
Posts: 131
Joined: Thu Aug 14, 2003 10:23 pm
Location: BUET
Contact:

some one help me to get 333 AC

Post by Riyad »

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
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN
User avatar
Riyad
Experienced poster
Posts: 131
Joined: Thu Aug 14, 2003 10:23 pm
Location: BUET
Contact:

hey for every body who is trying 333

Post by Riyad »

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
0-89237<space><space><space><space>-010-6 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 :wink: ) . 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
ravingavin
New poster
Posts: 21
Joined: Sun Sep 14, 2003 11:44 pm
Location: USA
Contact:

333 Clarification

Post by ravingavin »

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
helmet
New poster
Posts: 31
Joined: Tue Mar 02, 2004 11:55 am

Thank you Little Joey

Post by helmet »

Just a small thank you to lil Joey for the immense help his sample input/output gave.

(After majjar fight I got AC)
Just another brick in the wall...
Rony
New poster
Posts: 16
Joined: Wed Jun 30, 2004 6:46 am
Location: Dhaka
Contact:

333 ISBN numbers WA

Post by Rony »

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=len-1;i<j;i++,j--){
temp=str;
str=str[j];
str[j]=temp;
}
}
void check(char *s){

int i;
str_rev(str);
for(i=len-1;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+=str-48;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
dt96hasv
New poster
Posts: 5
Joined: Wed Oct 20, 2004 9:27 am
Location: Gothenburg
Contact:

Post by dt96hasv »

Testing your code with the following two examples:

Code: Select all

<tab><space>0823025713
082<space>3025713
The correct answer should be

Code: Select all

0823025713 is correct.
082<space>3025713 is incorrect.
While your program answers:

Code: Select all

<tab><space>0823025713 is correct.
082<space>3025713 is correct.
I.e. you have to treat tabs as whitespace also, and you also seems to have an issue with whitespaces embedded inside the ISBN-numbers.

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
Cahoun
New poster
Posts: 13
Joined: Mon Jan 03, 2005 2:34 pm
Location: Czech Republic
Contact:

Post by Cahoun »

Very good method is using gets method to read whole line input not scanf(%s\n",st).
Then you remove preceded and additional spaces.
Learn, learn, learn.
Jemerson
Learning poster
Posts: 59
Joined: Mon Feb 02, 2004 11:19 pm
Contact:

333 - Recognizing Good ISBNs

Post by Jemerson »

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:

Code: Select all

0-8104-5687-7 
0-8104-5687-7432
This   just    for test. 
0-1000-99999 
0-123-4567-89 
0-123-4567-890 
1-111-111-111
0-89237-010-6 
0-89237-010-6 TEST
XX-0000000000-XX 
XX000000XXX0000XXXXX 
1234567890
0823025713
013152447X
013152447x

082302571
08230257130
2803025713
07632200X1
 0823025713 
0823025713 
	0823025713 
0823025713	 
  	 0823025713		 
082 3025713 
0823025		713 
--08-2----302--5713------ 
082302_5713 
013152447X bla 
013-A-152447X 
0-1-3-1-5-2-4-4-7-X- - 
01315 
2447X
01-10 
01-434435 
01 0111 
The outputs suggested and also generated by my code were:

Code: Select all

0-8104-5687-7 is correct.
0-8104-5687-7432 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.
0-89237-010-6 is correct.
0-89237-010-6 TEST is incorrect.
XX-0000000000-XX 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.
--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.
01-10 is incorrect.
01-434435 is incorrect.
01 0111 is incorrect.
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.
Digit
New poster
Posts: 5
Joined: Sat Jan 15, 2005 7:06 pm

Post by Digit »

There are some differences to my output:

Your program says:
XX-0000000000-XX is correct.
XX000000XXX0000XXXXX is correct.

My (accepted) program says:
XX-0000000000-XX is incorrect.
XX000000XXX0000XXXXX is incorrect.
Post Reply

Return to “Volume 3 (300-399)”