Page 3 of 5
Posted: Thu Feb 28, 2008 6:07 pm
by turcse143
there r many problem in ur code.
look.
u should not take input by gets. because
if any spaces occur ur output is wrong.check this input.
Code: Select all
112233
30800
2937
323455693
5038297
112234
use scanf() instead of gets.
Code: Select all
for(i=0;i<length;i++)
{
if(i%2==0)
sum=sum+line[i]-48;
else
sum1=sum1+line[i]-48;
}
if(sum>sum1)
dif=sum-sum1;
else
dif=sum1-sum;
there are 1000 digit of input . u cannot check by %11.
Instead of it use Big Integer algorithm to solve it.
hope it helps.
Ok.....
Posted: Fri Feb 29, 2008 6:42 am
by Obaida
Thankx brother..... Decoded it.

Re: Ok.....
Posted: Fri Feb 29, 2008 8:13 am
by Obaida
I think you thought it by your way..... I know I can solve it by Big integer.... But I am trying to do this program in this system.... I think if I use recursive to every sub array then I can solve it.... then gets is not a problem.....

Posted: Fri Feb 29, 2008 7:25 pm
by turcse143
Big Integer algorithm depends upon you.
U design ur own way.
I think recursion is complex way to implement
for this problem. Because u can get RTE with the signal of
-- invalid memory reference
-- Divide by zero.
Instead of it. u can use this:
Code: Select all
b=0;
for(i=0;a[i];i++)
{
b=b*10+a[i]-48;
c=b%11;
b=c;
}
it may be reliable & implemented by me.
Re: 10929 - You can say 11
Posted: Mon Jul 20, 2009 7:05 am
by naseefcuet
Don't know why I am getting WA...Here is my code....
#include<stdio.h>
#include<string.h>
int main()
{
long long i,j,k,s;
char n[1000];
while(1)
{
s=0;
scanf("%s",&n);
i=strlen(n);
if(n[0]=='0' && n[1]=='\0')
break;
for(j=0;j<i;j++)
{
s=s*10+n[j]-'0';
}
if(s%11==0)
printf("%lld is a multiple of 11.\n",s);
else printf("%lld is not a multiple of 11.\n",s);
}
return 0;
}
plz help...............
Re:
Posted: Mon Mar 14, 2011 12:09 am
by DD
TISARKER wrote:According to jans Idea
Try this input
what is the correct output for above input.?
I don't think there is a input like this in the test data. My A.C. program cannot handle this.
Re: 10929 - You can say 11
Posted: Sun Apr 03, 2011 5:30 pm
by qriz
Why does Judge Fudge tells me he get Runtime Errors??
Code: Select all
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
public class Main
{
public static void main(String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
long odd,even;
BigInteger start;
do{
odd = 0;
even = 0;
String input = br.readLine();
if(input == "0")
return;
start = new BigInteger(input);
for(int i=0;i<input.length();i+=2)
{
even += (input.charAt(i)-48);
}
for(int i=1;i<input.length();i+=2)
{
odd += (input.charAt(i)-48);
}
if((even-odd)%11 == 0)
{
System.out.println(start + " is a multiple of 11.");
}
else
{
System.out.println(start + " is not a multiple of 11.");
}
}while(true);
}
}
plz, help me.. Slowly Im losing my mind..
Re: 10929 - You can say 11
Posted: Mon Jun 18, 2012 1:08 am
by PromeNabid
I tried with Big Integer approach. Did not work. Then I used forward O(n) approach with character array and got AC.
gets and scanf did not worked, i used cin instead.
Re:
Posted: Mon Jun 18, 2012 1:09 am
by PromeNabid
turcse143 wrote:Big Integer algorithm depends upon you.
U design ur own way.
I think recursion is complex way to implement
for this problem. Because u can get RTE with the signal of
-- invalid memory reference
-- Divide by zero.
Instead of it. u can use this:
Code: Select all
b=0;
for(i=0;a[i];i++)
{
b=b*10+a[i]-48;
c=b%11;
b=c;
}
it may be reliable & implemented by me.
It is very helpful. Thanks a lot.
Re: 10929 - You can say 11
Posted: Sun Sep 23, 2012 11:10 am
by darksk4
why WA?
can you determine why?
Code: Select all
#include<iostream>
using namespace std;
bool eleven(string number){
bool isEleven = true;
for(int counter = 0; counter < number.length() - 1; counter++){
if(number[counter] == '0')
continue;
while(true){
if(number[counter] == '1' && number[counter + 1] == '0'){
counter += 1;
break;
}
number[counter] -=1;
number[counter + 1 ] -= 1;
if(number[counter + 1] < '0'){
number[counter + 1] = '9';
number[counter] -= 1;
}
if(number[counter] == '0')
break;
}
}
int one2one = 0;
for(int counter = 0 ; counter < number.length(); counter++){
if(number[counter] != '0'){
isEleven = false;
}
if(number[counter] == '1'){
for(int base = counter + 1; base < number.length(); base++){
if(number[base] == '0')
one2one++;
else if(number[base] == '1')
break;
}
if(one2one == 0)
break;
else if(one2one % 2 == 0){
isEleven = true;
return isEleven;
}
}
}
return isEleven;
}
int main(){
string number;
while(cin >> number){
if(number == "0")
break;
if(eleven(number))
cout << number << " is a multiple of 11" << endl;
else
cout << number << " is not a multiple of 11" << endl;
}
return 0;
}
Re: 10929 - You can say 11
Posted: Tue Sep 25, 2012 1:51 am
by brianfry713
You're missing the period at the end of each line.
Re: 10929 - You can say 11
Posted: Tue Sep 25, 2012 4:39 am
by darksk4
brianfry713 wrote:You're missing the period at the end of each line.
Still WA @_@
Re: 10929 - You can say 11
Posted: Tue Sep 25, 2012 10:09 pm
by brianfry713
100 is not a multiple of 11.
Re: 10929 - You can say 11
Posted: Fri Oct 05, 2012 10:12 am
by vpanait
maybe i am wrong.. but i think the input contains inputs like "011", and considers them valid, after considering these cases i got AC
i hate this kinds of problems, instead of focusing on the algo, you need to focus on how to parse strange input..
Re: 10929 - You can say 11
Posted: Thu Oct 18, 2012 8:15 pm
by mgavin2
I don't care about "efficiency" or "doing it the right way"...
so how in the hell does this
not work???
Code: Select all
import java.math.BigInteger;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
BigInteger n = new BigInteger("1");
BigInteger elv = new BigInteger("11");
String l;
Scanner in = new Scanner(System.in);
while (true)
{
l = in.nextLine();
if (l.compareTo("0") == 0) break;
n = new BigInteger(l);
if (n.mod(elv).toString().compareTo("0") == 0)
System.out.println(n + " is a multiple of 11.");
else
System.out.println(n + " is not a multiple of 11.");
}
}
}
Maybe there's something secretly stopping BigInteger from working, unless you know everything about java
OMFG
GOT AC because of something really stupid.
instead of writing back out the number
Code: Select all
System.out.println(n + " is a multiple of 11.");
echo out the freakin read in string
Code: Select all
System.out.println(l + " is a multiple of 11.");
Hooray for input.