10929 - You can say 11
Moderator: Board moderators
-
- Experienced poster
- Posts: 106
- Joined: Thu Jan 29, 2004 12:07 pm
- Location: Bangladesh
- Contact:
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).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 ?
![:)](./images/smilies/icon_smile.gif)
-
- 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!
--thnx in advance!
(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....
-
- New poster
- Posts: 23
- Joined: Tue Sep 12, 2006 9:46 pm
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;
}
#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;
}
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.
You have to initialize sum1 & sum2 for every case, not only for the first case.
Ami ekhono shopno dekhi...
HomePage
HomePage
~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.
The problem states...
And remove the following unnecessary line
Hope these help.
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.The given numbers can contain up to 1000 digits
And remove the following unnecessary line
Code: Select all
system("pause");
Ami ekhono shopno dekhi...
HomePage
HomePage
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
HomePage
-
- 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]
[codeIt was accepted[/code]
Last edited by amine.hamdaoui on Sun Aug 12, 2007 10:57 pm, edited 1 time in total.
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
A string doesn't have to be zero-terminated. If you replacebyyou'll get accepted. Then, please, remove your code.
Code: Select all
if(line[0]=='0' && line[1]=='\0') break;
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.
Oh..........No...
Some one please help me this shouldn't be happened I m getting WA....please help me...
![:-?](./images/smilies/icon_confused.gif)
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.
This may be the address of success.