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 » Thu Jun 15, 2006 11:28 am

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 » Fri Jul 28, 2006 12:39 am

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). :)

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

10929--Algorithm

Post by dust_cover » Mon Oct 23, 2006 9:27 pm

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

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

Post by dust_cover » Mon Oct 23, 2006 10:28 pm

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 » Thu Jan 25, 2007 4:04 pm

#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 » Thu Jan 25, 2007 8:58 pm

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 » Fri Jan 26, 2007 2:53 pm

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 » Fri Jan 26, 2007 5:10 pm

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 » Sat Jan 27, 2007 6:03 pm

Thank you!!!!!!

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

Post by hridoy » Tue Jun 05, 2007 2:48 pm

How this algorithm works?

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

Post by Jan » Tue Jun 05, 2007 3:08 pm

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 » Thu Aug 09, 2007 6:36 pm

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.

User avatar
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey » Thu Aug 09, 2007 7:28 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;
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 » Tue Nov 20, 2007 2:41 pm

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 » Thu Feb 28, 2008 12:51 pm

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)”