10929 - You can say 11
Moderator: Board moderators
10929 - You can say 11
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
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
i'll be back
-
- New poster
- Posts: 42
- Joined: Fri Jun 13, 2003 3:47 pm
- Location: Dhaka , Bangladesh
- Contact:
I think there are no inputs like above.
I used gets() to take inputs. But There can be leading zeroes in the input.
Input:
So, change your code.
The code above is wrong. You should use this...
Hope it works.
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]=='0')
break;
....
Code: Select all
....
if(r[0]=='0'&&r[1]=='\0')
break;
....
Ami ekhono shopno dekhi...
HomePage
HomePage
According to jans Idea
Try this input
what is the correct output for above input.?
Try this input
Code: Select all
00000000
Mr. Arithmetic logic Unit
Re: Why WA
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;
-
- A great helper
- Posts: 481
- Joined: Sun Jun 19, 2005 1:18 am
- Location: European Union (Slovak Republic)
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.TISARKER wrote:According to jans Idea
Try this inputwhat is the correct output for above input.?Code: Select all
00000000
-
- New poster
- Posts: 37
- Joined: Fri Apr 30, 2004 6:52 pm
- Location: Portugal
I'm getting WA and have no clue what it might be
This is my function:
I sum the odd digits and subtract the even digits then check if the sum is divisible by 11. Did I miss something?
Thanks.
This is my function:
Code: Select all
code ACC and thus removed :P
Thanks.
Last edited by Schutzstaffel on Fri Jan 06, 2006 6:00 am, edited 1 time in total.
-
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact:
-
- New poster
- Posts: 37
- Joined: Fri Apr 30, 2004 6:52 pm
- Location: Portugal
-
- New poster
- Posts: 20
- Joined: Thu Jan 19, 2006 2:32 pm
10929 - You can say 11
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;
}
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;
}
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.
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.
-
- New poster
- Posts: 20
- Joined: Thu Jan 19, 2006 2:32 pm
Thanks you for your help. I got ACchunyi81 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.