All about problems in Volume 109. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Moderator: Board moderators
rimu
New poster
Posts: 9 Joined: Sat Feb 26, 2005 4:41 pm
Post
by rimu » 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
Thanks in advance for replying
i'll be back
arif_pasha
New poster
Posts: 42 Joined: Fri Jun 13, 2003 3:47 pm
Location: Dhaka , Bangladesh
Contact:
Post
by arif_pasha » Sun Oct 09, 2005 1:13 am
sorry above reply was mine..
Jan
Guru
Posts: 1334 Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:
Post
by Jan » 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:
So, change your code.
The code above is wrong. You should use this...
Code: Select all
....
if(r[0]=='0'&&r[1]=='\0')
break;
....
Hope it works.
TISARKER
Learning poster
Posts: 88 Joined: Tue Oct 12, 2004 6:45 pm
Location: Bangladesh
Contact:
Post
by TISARKER » Sun Oct 09, 2005 2:31 am
According to jans Idea
Try this input
what is the correct output for above input.?
Mr. Arithmetic logic Unit
iishaque
New poster
Posts: 5 Joined: Sun Apr 03, 2005 5:11 pm
Location: Dhaka, Bangladesh
Post
by iishaque » 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!!!!!
SRX
Learning poster
Posts: 63 Joined: Sat May 14, 2005 8:13 am
Location: Taiwan
Post
by SRX » 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]=='0'&&r[1]=='\0') break;
iishaque
New poster
Posts: 5 Joined: Sun Apr 03, 2005 5:11 pm
Location: Dhaka, Bangladesh
Post
by iishaque » Mon Oct 10, 2005 3:20 pm
Thank you SRX for you help. I got AC.
Martin Macko
A great helper
Posts: 481 Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)
Post
by Martin Macko » Sat Dec 10, 2005 10:23 pm
TISARKER wrote: According to jans Idea
Try this input
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.
Schutzstaffel
New poster
Posts: 37 Joined: Fri Apr 30, 2004 6:52 pm
Location: Portugal
Post
by Schutzstaffel » Fri Jan 06, 2006 4:49 am
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.
Last edited by
Schutzstaffel on Fri Jan 06, 2006 6:00 am, edited 1 time in total.
Krzysztof Duleba
Guru
Posts: 584 Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:
Post
by Krzysztof Duleba » Fri Jan 06, 2006 5:25 am
I don't think that using atoi on a not null-terminated string is safe.
Schutzstaffel
New poster
Posts: 37 Joined: Fri Apr 30, 2004 6:52 pm
Location: Portugal
Post
by Schutzstaffel » Fri Jan 06, 2006 6:00 am
You're right, it was because of that.
Thanks
athlon19831
New poster
Posts: 20 Joined: Thu Jan 19, 2006 2:32 pm
Post
by athlon19831 » 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[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;
}
chunyi81
A great helper
Posts: 293 Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore
Post
by chunyi81 » 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.
athlon19831
New poster
Posts: 20 Joined: Thu Jan 19, 2006 2:32 pm
Post
by athlon19831 » 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
Zaspire
New poster
Posts: 36 Joined: Sun Apr 23, 2006 2:42 pm
Location: Russia
Post
by Zaspire » Fri May 12, 2006 8:38 pm
Do not forget that you should output number with leading zeroes
(if it has)