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
Jemerson
Learning poster
Posts: 59
Joined: Mon Feb 02, 2004 11:19 pm
Contact:

Post by Jemerson »

Could you please tell me if you consider any X out of the 10th position a mistake?
Well, even correcting this my program keeps on WA. =( Extras cases?

Digit
New poster
Posts: 5
Joined: Sat Jan 15, 2005 7:06 pm

Post by Digit »

Yes, a 'X' may only appear at the 10th position.

Very Strange, don't know what else may be wrong.

BUT:
Your program says:
0-89237-010-6 TEST is incorrect.

My program says:
0-89237-010-6 TEST is correct.

Although '0-89237-010-6 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.

Karthekeyan
New poster
Posts: 33
Joined: Tue Jun 29, 2004 1:38 pm
Location: IITM,chennai,Tamil Nadu,India
Contact:

333 - PE - but why?

Post by Karthekeyan »

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[n-1]=='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

Sedefcho
A great helper
Posts: 374
Joined: Sun Jan 16, 2005 10:18 pm
Location: Bulgaria

Post by Sedefcho »

Hi Jemerson,

You can find below your Test Input and the Correct Output
for that Input.


INPUT

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 

OUTPUT

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 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.
--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.
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.

anisalamgir
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?

Post by anisalamgir »

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;
  }
:oops:
anis alamgir

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

Post by Raiyan Kamal »

hey, where did the headers go ?

Anyways, I have found your bug. Compare your output with my output. Hope this will help.

INPUT:

Code: Select all

0-89237-010-6
0-89237-010-----6
0-8-9-2-3-7-010-6
0-8306-3637-4      
  0-06-017758-6
    This_is_garbage
1-56884-030-6
    0-8230-2571-3
    0-345-31386-0
    0-671-88858-7
    0-8104-5687-7
    0-671-74119-5
    0-812-52030-0
    0-345-24865-1-150
0-452-26740-4
    0-13-139072-4
    0-1315-2447-X
XXXXXXXXXXX
-0-89237-010-6
-0-89237-010-6----
0-89235-010-8
0-89237-010-6

0-89237-010-6
MY OUTPUT:

Code: Select all

0-89237-010-6 is correct.
0-89237-010-----6 is correct.
0-8-9-2-3-7-010-6 is correct.
0-8306-3637-4 is correct.
0-06-017758-6 is correct.
This_is_garbage is incorrect.
1-56884-030-6 is correct.
0-8230-2571-3 is correct.
0-345-31386-0 is correct.
0-671-88858-7 is correct.
0-8104-5687-7 is correct.
0-671-74119-5 is correct.
0-812-52030-0 is correct.
0-345-24865-1-150 is incorrect.
0-452-26740-4 is correct.
0-13-139072-4 is correct.
0-1315-2447-X is correct.
XXXXXXXXXXX is incorrect.
-0-89237-010-6 is correct.
-0-89237-010-6---- is correct.
0-89235-010-8 is incorrect.
0-89237-010-6 is correct.
 is incorrect.
0-89237-010-6 is correct.
YOUR OUTPUR:

Code: Select all

0-89237-010-6 is correct.
0-89237-010-----6 is correct.
0-8-9-2-3-7-010-6 is correct.
0-8306-3637-4 is correct.
0-06-017758-6 is correct.
This_is_garbage is incorrect.
1-56884-030-6 is correct.
0-8230-2571-3 is correct.
0-345-31386-0 is correct.
0-671-88858-7 is correct.
0-8104-5687-7 is correct.
0-671-74119-5 is correct.
0-812-52030-0 is correct.
0-345-24865-1-150 is incorrect.
0-452-26740-4 is correct.
0-13-139072-4 is correct.
0-1315-2447-X is correct.
XXXXXXXXXXX is incorrect.
-0-89237-010-6 is correct.
-0-89237-010-6---- is correct.
0-89235-010-8 is incorrect.
0-89237-010-6 is correct.
0-89237-010-6 is correct.

Jemerson
Learning poster
Posts: 59
Joined: Mon Feb 02, 2004 11:19 pm
Contact:

Post by Jemerson »

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!

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

333 - Inputs examples

Post by Schutzstaffel »

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:

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
And got this output:

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 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.
--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.
Thanks
Image

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun »

My accepted code give

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 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.
--08-2----302--5713------ is correct.
082302_5713 is correct.
013152447X bla is correct.
013-A-152447X is incorrect.
0-1-3-1-5-2-4-4-7-X- - is correct.
01315 is incorrect.
2447X is incorrect.
01-10 is incorrect.
01-434435 is incorrect.
01 0111 is incorrect.
So there are differences. But you said you're getting RE. That's something else. Did you check other threads about this?

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

Post by Schutzstaffel »

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:

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 correct.
XX-0000000000-XX 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.
--08-2----302--5713------ is correct.
082302_5713 is correct.
013152447X bla is correct.
013-A-152447X is incorrect.
0-1-3-1-5-2-4-4-7-X- - is correct.
01315 is incorrect.
2447X is incorrect.
01-10 is incorrect.
01-434435 is incorrect.
01 0111 is incorrect.
The difference is only this line: 0-89237-010-6 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
Image

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun »

According to my implementation, only the ISBN's with uppercase characters are invalid except X which also should be nowhere else but at the 10th place.
You're getting RE. It's caused by invalid memory reference or division by 0. So at first get rid of RE then check for correctness.

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

Post by Schutzstaffel »

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.

Code: Select all

 
program got AC and thus code edited
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.
Last edited by Schutzstaffel on Tue Jan 03, 2006 9:47 pm, edited 1 time in total.
Image

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun »

I've got your problem. I'll let you find where it is. Try this

Code: Select all

0823025713
There is no leading or trailing space!!!!!!!!!
If you still don't know where it is, let me know.

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

Post by Schutzstaffel »

Does that mean my code crash on your computer with that input?
Hmm, it's weird, that input doesn't crash on my computer :o
I also checked the values of the arrays s1 and s2 and everything seems ok. :?
Thanks for your help.
Image

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun »

Schutzstaffel wrote:Does that mean my code crash on your computer with that input?
Yes, it does.
The key is that its length is exactly 10 and if you think so what? then check your terminating condition in while loop in verifyChars().

Post Reply

Return to “Volume 3 (300-399)”