Page 11 of 12

Re: 333 - Recognizing Good ISBNs - Need more In/Output sampl

Posted: Sat Jun 25, 2011 8:54 pm
by shovan.livebd
Hello there. I am facing problem with my code. It is giving PE and I can't find the reason. Could anyone help?

Code is given below:

Code: Select all

# include <stdio.h>

int main()
{
	char isbn[81];
	int digits[10];
	int s1, s2;
	int scanned;
	int delspace;
	int count;
	int i, c;

	while(gets(isbn))
	{
		count=0;
		scanned=0;
		delspace=0;

		for(i=0; isbn[i]; i++)
		{
			if(scanned==0)
				if(isbn[i]==' ' || isbn[i]=='\t')
				{
					for(c=0; isbn[c]; c++)
						isbn[c]=isbn[c+1];
					i--;
				}
				else scanned++;

			if(scanned==1)
			{
				if(isbn[i]>='0' && isbn[i]<='9')
				{
					if(count<10) digits[count]=isbn[i]-'0';
					count++;
				}
				else if(isbn[i]=='X' && count==9)
				{
					digits[count]=10;
					count++;
				}
				else if(isbn[i]==' ' || isbn[i]=='\t')
				{
					delspace=i;
					scanned++;
				}
				else if(isbn[i]!='-') break;
				if(count>10) break;
			}

			if(scanned==2)
				if(isbn[i]!=' ' && isbn[i]!='\t')
				{
					delspace=0;
					break;
				}
		}
		if(delspace) isbn[delspace]='\0';
		if(isbn[0]=='\0')
		{
			printf("is incorrect.\n");
			continue;
		}
		if(count!=10 || isbn[i])
		{
			printf("%s is incorrect.\n", isbn);
			continue;
		}

		s1=0; s2=0;
		for(i=0; i<10; i++)
		{
			s1+=digits[i];
			s2+=s1;
		}
		if(s2%11) printf("%s is incorrect.\n", isbn);
		else      printf("%s is correct.\n", isbn);
	}
	return 0;
}

333

Posted: Wed Nov 16, 2011 7:12 pm
by avatar
hellow.....someone please help me with problem 333
if there is any space inside the message .then what should i do..........
that is it correct or not????

Re: 333 - Recognizing Good ISBNs - Need more In/Output sampl

Posted: Wed Nov 16, 2011 7:18 pm
by avatar
hellow .....
please help me..
if there are more than 10 digit but there summation satisfies the given condition ..then what should i do????

Re: 333 - Recognizing Good ISBNs - Need more In/Output sampl

Posted: Wed Nov 16, 2011 7:20 pm
by avatar
hellow .....
please help me..
if there are more than 10 digit but there summation satisfies the given condition ..then what should i do????

Re: 333 - Recognizing Good ISBNs - Need more In/Output sampl

Posted: Sat Jul 28, 2012 1:59 pm
by uvasarker
Please, help me, I am getting W A continuously. Give me some hints or I/O.

Code: Select all

#include <cstdio>
#include <cstring>
#include <cctype>
int main()
{
		char in[500];
		//freopen("wtool.txt","r",stdin);
		//freopen("out-333.txt","w",stdout);
		while(gets(in))
		{
                int ln=strlen(in), ch=0, s1[500], ok=1, s2[500], total[500], len, hp=0, fag=0, f=0;
                len=ln;
				for(int i=0 ; i<ln ; i++)
				{
				    if( in[i]>='0' && in[i]<='9' )
				    {
				        s1[ch]=(int)in[i]-48;
				        ch++;
				    }
				    else if(in[i]=='X')
				    {
				        s1[ch]=10;
				        ch++;
				    }
				    else if(in[i]=='-' || in[i]==' ' )
				    {
				        ok=1;
				        if(in[i]=='-') hp++;
				    }
				}
                for(int i=0 ; i<ln ; i++){
				    if( (in[(ln-1)-i])==' ' && f==0 ) len--;
				    else f=1;
                }

				ln=len;
				s2[0]=s1[0];
				total[0]=s1[0];

				if(ch>0 )
				{
                        for(int i=1 ; i<ch ; i++)
                        {
                            s2[i]=s2[i-1]+s1[i];
                            total[i]=total[i-1]+s2[i];
                        }
                        for(int i=0 ; i<ln ; i++)
                        {
                            if(in[i]!=' ' && fag==0) fag=1;
                            if(  fag==1 ){
                                printf("%c",in[i]);
                            }
                        }
                        if(total[ch-1]%11==0) printf(" is correct.\n");
                        else printf(" is incorrect.\n");


				}
				else {
                        for(int i=0 ; i<len ; i++)
                        {
                            if(in[i]!=' ' && fag==0) fag=1;
                            if(  fag==1 ){
                                printf("%c",in[i]);
                            }
                        }
                        printf(" is incorrect.\n");
				}
		}

	return 0;
}

Anyone will explain please, why Uvatoolkit give these output:

Code: Select all

0 - 8923 7-010-6 is correct.
0-89237-10-6 is incorrect.
0-892...37-...010-6 is incorrect.
0-8()9237-010-6 is incorrect.

Re: 333 - Recognizing Good ISBNs - Need more In/Output sampl

Posted: Mon Jul 30, 2012 11:44 pm
by brianfry713
00000000X2 is incorrect.

Re: 333 - Recognizing Good ISBNs - Need more In/Output sampl

Posted: Tue Jul 31, 2012 8:54 am
by uvasarker
Guru,
Still WA.

Code: Select all

#include <cstdio>
#include <cstring>
#include <cctype>
int main()
{
      char in[500];
      //freopen("wtool.txt","r",stdin);
      //freopen("out-333.txt","w",stdout);
      while(gets(in))
      {
                int ln=strlen(in), ch=0, s1[500], ok=1, s2[500], total[500], len, hp=0, fag=0, f=0, pos=0;
                len=ln;
            for(int i=0 ; i<ln ; i++)
            {
                if( in[i]>='0' && in[i]<='9' )
                {
                    s1[ch]=(int)in[i]-48;
                    ch++;
                }
                else if(in[i]=='X')
                {
                    s1[ch]=10;
                    if(pos==0) pos=ch;
                    ch++;
                }
                else if(in[i]=='-' || in[i]==' ' )
                {
                    ok=1;
                    if(in[i]=='-') hp++;
                }
            }
                for(int i=0 ; i<ln ; i++){
                if( (in[(ln-1)-i])==' ' && f==0 ) len--;
                else f=1;
                }

            ln=len;
            s2[0]=s1[0];
            total[0]=s1[0];

            if(ch==10 && pos==10 )
            {
                        for(int i=1 ; i<ch ; i++)
                        {
                            s2[i]=s2[i-1]+s1[i];
                            total[i]=total[i-1]+s2[i];
                        }
                        for(int i=0 ; i<ln ; i++)
                        {
                            if(in[i]!=' ' && fag==0) fag=1;
                            if(  fag==1 ){
                                printf("%c",in[i]);
                            }
                        }
                        if(total[ch-1]%11==0) printf(" is correct.\n");
                        else printf(" is incorrect.\n");


            }
            else {
                        for(int i=0 ; i<len ; i++)
                        {
                            if(in[i]!=' ' && fag==0) fag=1;
                            if(  fag==1 ){
                                printf("%c",in[i]);
                            }
                        }
                        printf(" is incorrect.\n");
            }
      }

   return 0;
}


Re: 333 - Recognizing Good ISBNs - Need more In/Output sampl

Posted: Wed Aug 01, 2012 3:18 am
by brianfry713
Doesn't match the sample I/O.

Re: 333 - Recognizing Good ISBNs - Need more In/Output sampl

Posted: Wed Sep 18, 2013 6:59 pm
by techbd123
Guru! Brianfry!
Please help me. I used most of the critical cases but found WA. Please help
My code is here: http://ideone.com/AD8rfT

Re: 333 - Recognizing Good ISBNs - Need more In/Output sampl

Posted: Thu Sep 19, 2013 12:32 am
by brianfry713
For your 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 
0131524     47X
0_1_31524_47X
0131524 	47X
013152447X
0123456789X
My AC 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 correct.
 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.
0131524     47X is incorrect.
0_1_31524_47X is incorrect.
0131524 	47X is incorrect.
013152447X is correct.
0123456789X is incorrect.

333 - Recognizing Good ISBNs

Posted: Sun Mar 23, 2014 8:32 pm
by cyberdragon

Re: 333 - Recognizing Good ISBNs

Posted: Tue Mar 25, 2014 12:18 am
by brianfry713
Try running your code on the sample input. Don't try to compile C++ code using a JAVA compiler.

Re: 333 - Recognizing Good ISBNs

Posted: Wed Mar 26, 2014 7:06 am
by cyberdragon
Well that was a bad mistake using getline.
But still don't know why WA after editing.

http://ideone.com/LkQpA5

Re: 333 - Recognizing Good ISBNs

Posted: Wed Mar 26, 2014 8:34 pm
by brianfry713
00000000X2 is incorrect.

Re: 333 - Recognizing Good ISBNs

Posted: Thu Mar 27, 2014 4:14 am
by cyberdragon
In case of 00000000X2, s2 = 22 which is evenly divisible by 11.
Or does "evenly divisible" is different from "divisible" ?