Page 3 of 12

GIVE ME SOME INPUT

Posted: Sat Aug 10, 2002 8:48 am
by NONAME_SUST
Heloo,
I ahve solved the problem which is valid for all given inputs. But when I submit it I got wrong answer. Can anyone give me some crutial inputs to judge the problem???

333 ISBN (**GOT WA~^_*...)

Posted: Sat Aug 17, 2002 4:03 pm
by hank
What's wrong in my source?

help me!!
thanks!

[c]
#include "stdio.h"
void print_it(char *s)
{
int i,j;
for(i=0;i<strlen(s);i++)
{
if( s!='\t' && s!=' ' )
break;
else
s=1;
}

for(i=strlen(s)-1;i>=0;i--)
{
if( s!='\t' && s!=' ' )
break;
else
s=1;
}
j=0;
for(i=0;i<strlen(s);i++)
{
if( s!=1&&s!='\t'&&s!=' ') {printf("%c",s);j=1;}

}
if(j==1) printf(" ");

}
void main()
{
char a[1000];
int n,i;
int p[1000],q[1000],r[1000];
while( gets(a) )
{
print_it(a);
n=0;
for(i=0;i<strlen(a);i++)
{
if( a[i]>='0'&&a[i]<='9' )
{
n++;
p[n-1]=a[i]-'0';
}
else if( a[i]=='X' && n==9 )
{
n++;
p[n-1]=10;
}
else if( a[i]!=' ' && a[i]!='-' && a[i]!='\t' )
{
printf("is incorrect.\n");
goto read_next;
}
}

if( n!=10 ) {printf("is incorrect.\n");goto read_next;}

q[0]=p[0];
for(i=1;i<10;i++)
q[i]=q[i-1]+p[i];
r[0]=q[0];
for(i=1;i<10;i++)
r[i]=r[i-1]+q[i];
if(r[9]!=0&&r[9]%11==0) printf("is correct.\n");

read_next:
}
}[/c]

Posted: Wed Sep 18, 2002 2:25 am
by nicopadu
Some little questions...

1. Hyphens can be anywere. (including two hyphens at the middle of the isbn number, like --0--1315--2447-X--???)

2. The ISBN cannot be less than 10 symbols long (of course, excluding hyphens) but can be more than 10 symbols. (what kind of symbols can i accept excluiding numbers, X's, hyphens and spaces???) (this isbn is correct: 0000000011053???)

3. There can be leading/trailing spaces and tabs. (ok!!!)

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'). (ok!!!)

thanks!

Posted: Sat Sep 21, 2002 4:54 am
by hank
I got WA at this problem many times.
But I don't know why...
It is very strange.
:cry:

#333: Recognizing Good ISBNs - WA

Posted: Sun Nov 03, 2002 8:58 am
by ec3_limz
Can anyone tell me why my program gets a WA?

I was so sure that I was correct!

[cpp]#include <stdio.h>
#include <string.h>

int main() {
bool valid;
char isbn[81];
int len, sum, sum2, i, j;

while (scanf("%s", &isbn) == 1) {
valid = true;
sum = sum2 = 0;
len = strlen(isbn);
for (i = 0, j = 0; i < len; i++) {
if (isbn >= '0' && isbn <= '9') {
sum += isbn - '0';
sum2 += sum;
j++;
}
else if (isbn == 'X') {
sum += 10;
sum2 += sum;
j++;
}
else if (isbn != '-') {
valid = false;
break;
}
}
if (valid)
valid = (j == 10 && sum2 % 11 == 0);

printf("%s is %s.\n", isbn, valid ? "correct" : "incorrect");
}

return 0;
}[/cpp]

333 - ISBN format question

Posted: Thu Nov 07, 2002 2:41 am
by Archer
About the ISBN parser: What is it supposed to do if more than 10 digits appear in the input? Say "invalid ISBN"? or regard only the first 10 digits and proceed as normal?

Posted: Sun Dec 01, 2002 9:55 pm
by Per
Input:
0-8104-5687-7
0-8104-5687-7432
Output:
0-8104-5687-7 is correct.
0-8104-5687-7432 is incorrect.
So more than 10 digits can never be a valid ISBN.

you got one big problem

Posted: Fri Dec 13, 2002 10:43 pm
by epsilon0
it looks correct, it seems correct, it tastes correct too, but it's not correct.

guess where the problem lies... hehe if you could i weren't writing this.

you have a pretty smart way to perform the check. but let this smartness not occult the flaws of your design.

think about it:

000-000-071-X

this is a good code because 7*3 + 1*2 + 10 = 33 = 0 (% 11)

let's get to the heart of the "mystery" now:

000-000-00X-2

clearly 10*2 + 2 = 22 = 0 (% 11)

so your program would aknowledge such a code, although there is an 'X' where there should not be.

i guess your faith made you blind. once you decided your program was divine, you could not perceive the flaws anymore.

your program once modified would look like:

[c]if (code == X)
{
if (i != 10)
{
valid = FALSE;
break;
}
sum += 10;
sum2 += sum;
}[/c]

i don't recall all your variables names sorry about it BUT you get the idea. shouldn't be a big deal to handle now you've been enlightened.

Posted: Fri Dec 13, 2002 10:52 pm
by epsilon0
no way.

an ISBN has EXACTLY ten "digits" (including the checking character in the end).

Posted: Fri Dec 13, 2002 10:55 pm
by epsilon0
using 13,000 bytes of data memory to solve such a program, is wrong.

Posted: Mon Dec 30, 2002 2:11 am
by yahoo
Dear ec3-limz you have used scanf to take input but input may be string just like: " This is right" . In this case your program may fail. So try to use gets(); I think this can help you. :lol: :lol:

about P.E.

Posted: Wed Jan 29, 2003 2:10 pm
by supermin
I got AC(P.E.) with this problem 333.
But I can't find any wrong.I think the "(in)correct." is not the problem.

This is my thougt:

Ignore the spaces in front of the string,and output the followings.

Code: Select all

        char temp[100],prob[100],*p;
        int i;

        gets(temp);
        i=0;
        p=temp;
        while(isspace(temp[i])) i++;
        strcpy(prob,p+i);

        printf("%s is (in)correct.\n",prob);
ex:
01-10
01-434435
01 0111

I will output:

01-10 is (in)correct.
01-434435 is (in)correct.
01 0111 is (in)correct.

There is any wrong with my thought?

333: WA, why?

Posted: Sat Mar 01, 2003 3:20 pm
by kurnia w
Hi...can anybody help me what kind of input that make my code WA ??
0-89237-010-6 is correct, how about 0_89237_010_6 ??
anyway here is my code
[c]#include<stdio.h>
#include<string.h>

void main() {
char isbn[81];
int sum1[10],sum2[10],i,length,angka[10],max,flag;

while(scanf("%s",&isbn)==1) {
printf("%s",isbn);
length=strlen(isbn); max=0;
for(i=0; i<length; i++) {
if(max==10) { flag=0; break; }
if((isbn>=47 && isbn<=58) || isbn==45 || isbn==88) {
if(isbn=='X') angka[max++]=10;
if(isbn>=47 && isbn<=58) {
angka[max++]=isbn-'0';
flag=1;
}
}
else { flag=0; break; }
}
if(max==10 && flag==1) {
sum1[0]=angka[0];
for(i=0; i<10; i++) {
sum1[i+1]=(sum1+angka[i+1]);
}
sum2[0]=sum1[0];
for(i=0; i<10; i++) {
sum2[i+1]=(sum2+sum1[i+1]);
}
if(sum2[9]%11==0) flag=1;
else flag=0;
}

if(flag==1 && max==10) printf(" is correct.\n");
else printf(" is incorrect.\n");
}
}
[/c]
Thank's....

Posted: Sun Mar 02, 2003 2:30 am
by yahoo
By taking a glance to your program i see that you can't handle string input like " I am a boy".
Ouput should be I am a boy not correct
But i think your program will give I is incorrect.
Try to use gets instead of scanf.
Hope it helps.

Posted: Sun Mar 02, 2003 7:07 am
by kurnia w
I'm already fixed it, but still got WA?? why ??