Page 2 of 5

Posted: Thu Jun 15, 2006 11:28 am
by Raiyan Kamal
If you just add/substract alternative digits and chek the final sum, then leading zeroes are not supposed to create any problem. Why are a lot of people so worried about the leading zeroes ?

Posted: Fri Jul 28, 2006 12:39 am
by sml
Raiyan Kamal wrote:If you just add/substract alternative digits and chek the final sum, then leading zeroes are not supposed to create any problem. Why are a lot of people so worried about the leading zeroes ?
Because a lot of us were checking input[0] for '0', and exiting the program in the event that it was true. I had the same basic problem, though I was glad my algorithm was correct (without cheating! Not that there are many threads on this subject). :)

10929--Algorithm

Posted: Mon Oct 23, 2006 9:27 pm
by dust_cover
can someone tell me how the algorithm described above

(sum of odd digits-sum of even digits) works for 22?
It is a bit confusing for me!
--thnx in advance!

Posted: Mon Oct 23, 2006 10:28 pm
by dust_cover
Hi I got the problem & got AC!
No need to explain!
Thanx Anyways!
:D

10929 - You can say 11

Posted: Thu Jan 25, 2007 4:04 pm
by Waddle
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int sum1=0,sum2=0,k,i,j;
char a[1000];
while(1)
{
gets(a);
if(a[0]=='0'&& a[1]=='\0')
return 0;
k=strlen(a);

for(i=0;i<k;i=i+2)
sum1=sum1+a[i]-48;
for(j=1;j<k;j=j+2)
sum2=sum2+a[j]-48;

if((sum1-sum2)%11==0)
{
printf("%s is a multiple of 11.\n",a);
}
else
{
printf("%s is not a multiple of 11.\n",a);
}
}
return 0;
}

Posted: Thu Jan 25, 2007 8:58 pm
by Jan
Search your problem first. Dont open a new thread if there is one already.

You have to initialize sum1 & sum2 for every case, not only for the first case.

~O~ I don't really understand what you say...

Posted: Fri Jan 26, 2007 2:53 pm
by Waddle
The code has been removed.

Posted: Fri Jan 26, 2007 5:10 pm
by Jan
The problem states...
The given numbers can contain up to 1000 digits
So, to store it in an array of characters you need 1000 + 1 elements. The last '1' is for a NULL character. So, increase your array size.
And remove the following unnecessary line

Code: Select all

system("pause"); 
Hope these help.

Posted: Sat Jan 27, 2007 6:03 pm
by Waddle
Thank you!!!!!!

Posted: Tue Jun 05, 2007 2:48 pm
by hridoy
How this algorithm works?

Posted: Tue Jun 05, 2007 3:08 pm
by Jan
It's a school time technique. An integer is divisible by 11 if the difference between 'the summation of the odd positioned digits' and 'the summation of the even positioned digits' is divisible by 11.

Output Limit exceeded

Posted: Thu Aug 09, 2007 6:36 pm
by amine.hamdaoui
Why do i have Output Limit exceeded?!!!!
[codeIt was accepted[/code]

Posted: Thu Aug 09, 2007 7:28 pm
by little joey
A string doesn't have to be zero-terminated. If you replace

Code: Select all

if(line[0]=='0' && line[1]=='\0') break; 
by

Code: Select all

if((line.size()==1)&&(line[0]=='0')) break;
you'll get accepted. Then, please, remove your code.

where's wrong in the code?

Posted: Tue Nov 20, 2007 2:41 pm
by apurba

Code: Select all

removed after ac

Oh..........No...

Posted: Thu Feb 28, 2008 12:51 pm
by Obaida
Some one please help me this shouldn't be happened I m getting WA....please help me... :-?

Code: Select all

removed