Page 1 of 5

### 10929 - You can say 11

Posted: Sun Oct 09, 2005 12:54 am
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

Posted: Sun Oct 09, 2005 1:13 am
sorry above reply was mine.. Posted: Sun Oct 09, 2005 2:16 am
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``````

Code: Select all

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

Code: Select all

``````....
if(r=='0'&&r=='\0')
break;
....``````
Hope it works. Posted: Sun Oct 09, 2005 2:31 am
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
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
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'&&r=='\0') break;
``````

### thanks

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

Posted: Sat Dec 10, 2005 10:23 pm
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
I'm getting WA and have no clue what it might be 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
I don't think that using atoi on a not null-terminated string is safe.

Posted: Fri Jan 06, 2006 6:00 am
You're right, it was because of that.
Thanks ### 10929 - You can say 11

Posted: Sat Jan 28, 2006 8:31 am
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;
int s_odd,s_even;
int s;
int i,j;
while(cin>>str)
{
if(strcmp(str,"0")==0)
break;
else if(str=='-')
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
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
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
Do not forget that you should output number with leading zeroes (if it has)