## 10929 - You can say 11

Moderator: Board moderators

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Contact:
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 ?

sml
New poster
Posts: 15
Joined: Mon Jul 24, 2006 3:34 pm
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).

dust_cover
New poster
Posts: 23
Joined: Tue Sep 12, 2006 9:46 pm

### 10929--Algorithm

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!
i wanna give it a try....

dust_cover
New poster
Posts: 23
Joined: Tue Sep 12, 2006 9:46 pm
Hi I got the problem & got AC!
No need to explain!
Thanx Anyways!
i wanna give it a try....

New poster
Posts: 22
Joined: Thu Jan 25, 2007 3:54 pm
Location: Taiwan
Contact:

### 10929 - You can say 11

#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;
}

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:

You have to initialize sum1 & sum2 for every case, not only for the first case.
Ami ekhono shopno dekhi...
HomePage

New poster
Posts: 22
Joined: Thu Jan 25, 2007 3:54 pm
Location: Taiwan
Contact:

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

The code has been removed.
Last edited by Waddle on Wed Jun 06, 2007 3:05 pm, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
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.
Ami ekhono shopno dekhi...
HomePage

New poster
Posts: 22
Joined: Thu Jan 25, 2007 3:54 pm
Location: Taiwan
Contact:
Thank you!!!!!!

hridoy
New poster
Posts: 21
Joined: Tue May 08, 2007 10:30 am
Location: Dhaka
Contact:
How this algorithm works?

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
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.
Ami ekhono shopno dekhi...
HomePage

amine.hamdaoui
New poster
Posts: 10
Joined: Tue Aug 07, 2007 7:33 pm

### Output Limit exceeded

Why do i have Output Limit exceeded?!!!!
[codeIt was accepted[/code]
Last edited by amine.hamdaoui on Sun Aug 12, 2007 10:57 pm, edited 1 time in total.

little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm
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;``
The biggest problem with most problems is not how to solve the problem, but how to not solve what is not the problem.

apurba
New poster
Posts: 42
Joined: Sun Oct 07, 2007 10:29 pm

### where's wrong in the code?

Code: Select all

``````removed after ac
``````

Code: Select all

``keep dreaming...``

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
``removed``