Page 1 of 5

10929 - You can say 11

Posted: Sun Oct 09, 2005 12:54 am
by rimu
i'm very confused getting WA :(

can anybody post some critical i/o

my logic is as follows in brief:


gets( r );

for ( i = s = 0; r; ++i )
{
s = s * 10 + r - 48;
s = s % 11;
}

if ( !s ) then multiple

Thanks in advance for replying

Posted: Sun Oct 09, 2005 1:13 am
by arif_pasha
sorry above reply was mine.. :)

Posted: Sun Oct 09, 2005 2:16 am
by Jan
I think there are no inputs like above.

I used gets() to take inputs. But There can be leading zeroes in the input.

Input:

Code: Select all

011
11
122321
0123123
0
So, change your code.

Code: Select all

....
    if(r[0]=='0')
        break;
....
The code above is wrong. You should use this...

Code: Select all

....
    if(r[0]=='0'&&r[1]=='\0')
        break;
....
Hope it works. :D

Posted: Sun Oct 09, 2005 2:31 am
by TISARKER
According to jans Idea
Try this input

Code: Select all

00000000
what is the correct output for above input.?

Why WA

Posted: Sun Oct 09, 2005 5:00 pm
by iishaque
Plz give some critical input and output. Can any one tell Is rimu's algorithm right or wrong??
Plz help!!!!!

Re: Why WA

Posted: Sun Oct 09, 2005 5:08 pm
by SRX
iishaque wrote:Plz give some critical input and output. Can any one tell Is rimu's algorithm right or wrong??
Plz help!!!!!

Code: Select all

     just count num's odd digits sum - num's even digits sum 
     then check it%11 
     then use Jan's way ( thanks  :D ) if(r[0]=='0'&&r[1]=='\0') break;  

thanks

Posted: Mon Oct 10, 2005 3:20 pm
by iishaque
Thank you SRX for you help. I got AC.

Posted: Sat Dec 10, 2005 10:23 pm
by Martin Macko
TISARKER wrote:According to jans Idea
Try this input

Code: Select all

00000000
what is the correct output for above input.?
The 0000000 is not positive, so it may be only at the end of the input. But it's not because my AC recognized the end of the input by a single 0 in line.

Posted: Fri Jan 06, 2006 4:49 am
by Schutzstaffel
I'm getting WA and have no clue what it might be :o

This is my function:

Code: Select all

code ACC and thus removed :P
I sum the odd digits and subtract the even digits then check if the sum is divisible by 11. Did I miss something?
Thanks.

Posted: Fri Jan 06, 2006 5:25 am
by Krzysztof Duleba
I don't think that using atoi on a not null-terminated string is safe.

Posted: Fri Jan 06, 2006 6:00 am
by Schutzstaffel
You're right, it was because of that.
Thanks :P

10929 - You can say 11

Posted: Sat Jan 28, 2006 8:31 am
by athlon19831
I got Time Limit Exceeded,but i don't know why
my code:
#include "iostream.h"
#include "stdio.h"
#include "string.h"
#include "math.h"
int main(int argc, char* argv[])
{
char str[1010];
int s_odd,s_even;
int s;
int i,j;
while(cin>>str)
{
if(strcmp(str,"0")==0)
break;
else if(str[0]=='-')
break;
else
{
s_odd=0;
s_even=0;
for(i=0;i<strlen(str);i++)
{
if(i%2)
{
s_odd+=(int(str)-48);
}
else
{
s_even+=(int(str)-48);
}
}
s=int(fabs(s_odd-s_even));
if(s==0)
{
for(i=0;i<strlen(str);i++)
{
cout<<str;
}
cout<<" is a multiple of 11."<<endl;
}
else if(s%11==0)
{
for(i=0;i<strlen(str);i++)
{
cout<<str;
}
cout<<" is a multiple of 11."<<endl;
}
else
{
for(i=0;i<strlen(str);i++)
{
cout<<str;
}
cout<<" is not a multiple of 11."<<endl;
}
}
}
return 0;
}

Posted: Sat Jan 28, 2006 9:03 am
by chunyi81
You are calling strlen each time in the for loop you print the input number. And in fact, you can print out a char array directly just like C++ strings.

Just do a cout << str for the places where you print the input number character by character and the TLE should go away.

If not, you might wan to consider scanf/printf rather cin/cout.

Hope this helps.

Posted: Sat Jan 28, 2006 1:11 pm
by athlon19831
chunyi81 wrote:You are calling strlen each time in the for loop you print the input number. And in fact, you can print out a char array directly just like C++ strings.

Just do a cout << str for the places where you print the input number character by character and the TLE should go away.

If not, you might wan to consider scanf/printf rather cin/cout.

Hope this helps.
Thanks you for your help. I got AC :)

Posted: Fri May 12, 2006 8:38 pm
by Zaspire
Do not forget that you should output number with leading zeroes :evil: (if it has)