10929 - You can say 11

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

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

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

Post 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). :)
dust_cover
New poster
Posts: 23
Joined: Tue Sep 12, 2006 9:46 pm

10929--Algorithm

Post 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!
i wanna give it a try....
dust_cover
New poster
Posts: 23
Joined: Tue Sep 12, 2006 9:46 pm

Post by dust_cover »

Hi I got the problem & got AC!
No need to explain!
Thanx Anyways!
:D
i wanna give it a try....
Waddle
New poster
Posts: 22
Joined: Thu Jan 25, 2007 3:54 pm
Location: Taiwan
Contact:

10929 - You can say 11

Post 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;
}
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post 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.
Ami ekhono shopno dekhi...
HomePage
Waddle
New poster
Posts: 22
Joined: Thu Jan 25, 2007 3:54 pm
Location: Taiwan
Contact:

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

Post by Waddle »

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
Location: Dhaka, Bangladesh
Contact:

Post 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.
Ami ekhono shopno dekhi...
HomePage
Waddle
New poster
Posts: 22
Joined: Thu Jan 25, 2007 3:54 pm
Location: Taiwan
Contact:

Post by Waddle »

Thank you!!!!!!
hridoy
New poster
Posts: 21
Joined: Tue May 08, 2007 10:30 am
Location: Dhaka
Contact:

Post by hridoy »

How this algorithm works?
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post 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.
Ami ekhono shopno dekhi...
HomePage
amine.hamdaoui
New poster
Posts: 10
Joined: Tue Aug 07, 2007 7:33 pm

Output Limit exceeded

Post by amine.hamdaoui »

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

Post 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.
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?

Post by apurba »

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
Location: (BUBT) Dhaka,Bagladesh.

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

Post by Obaida »

Some one please help me this shouldn't be happened I m getting WA....please help me... :-?

Code: Select all

removed
Last edited by Obaida on Wed Mar 18, 2009 6:26 am, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.
Post Reply

Return to “Volume 109 (10900-10999)”