333 - Recognizing Good ISBNs
Moderator: Board moderators
-
- Experienced poster
- Posts: 167
- Joined: Fri Oct 19, 2001 2:00 am
- Location: Saint Petersburg, Russia
-
- Experienced poster
- Posts: 167
- Joined: Fri Oct 19, 2001 2:00 am
- Location: Saint Petersburg, Russia
It's difficult to say what's wrong. There were some tricks in this problem (AFAIR):
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').
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').
I thnik 333 is not difficult, but I got WA.
Can anyone tell me what is wrong with my code?
#include <stdio.h>
#include <string.h>
#include <ctype.h>
main()
{
int i,j,k,incorrect,isbn[3000],s1[3000],s2[3000];
char line[3000];
while (scanf("%s",line)==1)
{
incorrect=0;
for (i=0;i<3000;i++) isbn=0;
k=strlen(line);
for (i=0,j=0;i<k;i++)
{
if (line=='-') continue;
if (isdigit(line)) isbn[j++]=line-'0';
else
if (line=='X')
if (j==9) isbn[j++]=10;
else { incorrect=1; break; }
}
if (j!=10) incorrect=1;
else
{
s1[0]=isbn[0];
for (i=1;i<10;i++) s1=s1[i-1]+isbn;
s2[0]=s1[0];
for (i=1;i<10;i++) s2=s2[i-1]+s1;
if (s2[9]%11!=0) incorrect=1;
}
if (incorrect) printf("%s is incorrect.n",line);
else printf("%s is correct.n",line);
}
return 0;
}
Can anyone tell me what is wrong with my code?
#include <stdio.h>
#include <string.h>
#include <ctype.h>
main()
{
int i,j,k,incorrect,isbn[3000],s1[3000],s2[3000];
char line[3000];
while (scanf("%s",line)==1)
{
incorrect=0;
for (i=0;i<3000;i++) isbn=0;
k=strlen(line);
for (i=0,j=0;i<k;i++)
{
if (line=='-') continue;
if (isdigit(line)) isbn[j++]=line-'0';
else
if (line=='X')
if (j==9) isbn[j++]=10;
else { incorrect=1; break; }
}
if (j!=10) incorrect=1;
else
{
s1[0]=isbn[0];
for (i=1;i<10;i++) s1=s1[i-1]+isbn;
s2[0]=s1[0];
for (i=1;i<10;i++) s2=s2[i-1]+s1;
if (s2[9]%11!=0) incorrect=1;
}
if (incorrect) printf("%s is incorrect.n",line);
else printf("%s is correct.n",line);
}
return 0;
}
the next line wrong, beacause if there is gap between 2 part in line, your program handle it as 2 line.
while (scanf("%s",line)==1)
for example:
This is a wrong line
Your program generate 5 output line instead of 1.
You should use while(gets(line)) and search the start, and the end of the isbn in the line.
while (scanf("%s",line)==1)
for example:
This is a wrong line
Your program generate 5 output line instead of 1.
You should use while(gets(line)) and search the start, and the end of the isbn in the line.
Can someone tell me what is wrong with this code?
[cpp]
#include <cstdio>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
using namespace std;
void main()
{
char B[1000],S[500];
bool GoodISBN;
int i,j;
vector<int> ISBN;
while(fgets(B,1000,stdin)!=NULL)
{
GoodISBN=true;
ISBN.clear();
for(i=0;i<strlen(B);i++)
{
if(!isdigit(B)
&&B!=' '
&&B!='-'
&&B!='X'
&&B!='\n'
&&B!='\t')
{
GoodISBN=false;
break;
}
if(isdigit(B))
{
ISBN.push_back(B-'0');
}
if(B=='X')
{
ISBN.push_back(10);
if(ISBN.size()!=10)
{
GoodISBN=false;
break;
}
}
}
if(GoodISBN)
{
if(ISBN.size()!=10)
{
GoodISBN=false;
}
j=0;
for(i=0;i<ISBN.size();i++)
{
j+=ISBN*(10-i);
}
if(j%11!=0)
{
GoodISBN=false;
}
}
strcpy(S,"");
sscanf(B,"%s",S);
if(GoodISBN)
{
printf("%s is correct.\n",S);
}
else
{
printf("%s is incorrect.\n",S);
}
}
}[/cpp]
[cpp]
#include <cstdio>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
using namespace std;
void main()
{
char B[1000],S[500];
bool GoodISBN;
int i,j;
vector<int> ISBN;
while(fgets(B,1000,stdin)!=NULL)
{
GoodISBN=true;
ISBN.clear();
for(i=0;i<strlen(B);i++)
{
if(!isdigit(B)
&&B!=' '
&&B!='-'
&&B!='X'
&&B!='\n'
&&B!='\t')
{
GoodISBN=false;
break;
}
if(isdigit(B))
{
ISBN.push_back(B-'0');
}
if(B=='X')
{
ISBN.push_back(10);
if(ISBN.size()!=10)
{
GoodISBN=false;
break;
}
}
}
if(GoodISBN)
{
if(ISBN.size()!=10)
{
GoodISBN=false;
}
j=0;
for(i=0;i<ISBN.size();i++)
{
j+=ISBN*(10-i);
}
if(j%11!=0)
{
GoodISBN=false;
}
}
strcpy(S,"");
sscanf(B,"%s",S);
if(GoodISBN)
{
printf("%s is correct.\n",S);
}
else
{
printf("%s is incorrect.\n",S);
}
}
}[/cpp]
333 rejudgement??
So I woke up this morning, and found the Judge gave me one less problem solved than my own administration accounted for.
Checked, rechecked and double checked my mail, but no rejudgement notice.
Then compared all the problemnumbers in the Judge's solved-list against my own and discovered 333 was missing!
What is going on? Out of 3429 submissions, only ONE has AC. Can this really be true? And what about a rejudgement notice?
A very sad,
-xenon
Checked, rechecked and double checked my mail, but no rejudgement notice.
Then compared all the problemnumbers in the Judge's solved-list against my own and discovered 333 was missing!
What is going on? Out of 3429 submissions, only ONE has AC. Can this really be true? And what about a rejudgement notice?
A very sad,
-xenon
Hmm.
Did you already dig deeper into the possible change? First inspection shows no change in the problem description. No warning sign with additional notes either, so I guess we're in the dark.
In a file I keep for making statistics, I found that some weeks ago there were some 600 people with AC on this problem. In my opinion it is a little harsh to sweep them all off by a rejudge, since that implicitly means they all misunderstood the problem
But... such is life.
Still crying in the rain,
-xenon
Did you already dig deeper into the possible change? First inspection shows no change in the problem description. No warning sign with additional notes either, so I guess we're in the dark.
In a file I keep for making statistics, I found that some weeks ago there were some 600 people with AC on this problem. In my opinion it is a little harsh to sweep them all off by a rejudge, since that implicitly means they all misunderstood the problem
![:-?](./images/smilies/icon_confused.gif)
But... such is life.
Still crying in the rain,
-xenon