## 10929 - You can say 11

Moderator: Board moderators

there r many problem in ur code.
look.
Code: Select all
`while(gets(line))`

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`

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.
''I want to be most laziest person in the world''
turcse143
Learning poster

Posts: 81
Joined: Wed May 09, 2007 9:59 pm

### Ok.....

Thankx brother..... Decoded it.
try_try_try_try_&&&_try@try.com
This may be the address of success.
Obaida
A great helper

Posts: 380
Joined: Wed Jan 16, 2008 6:51 am

### Re: Ok.....

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.....
try_try_try_try_&&&_try@try.com
This may be the address of success.
Obaida
A great helper

Posts: 380
Joined: Wed Jan 16, 2008 6:51 am

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.
''I want to be most laziest person in the world''
turcse143
Learning poster

Posts: 81
Joined: Wed May 09, 2007 9:59 pm

### Re: 10929 - You can say 11

Don't know why I am getting WA...Here is my code....[code][/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...............
naseefcuet
New poster

Posts: 2
Joined: Mon Jul 20, 2009 6:53 am

### Re:

TISARKER wrote:According to jans Idea
Try this input
Code: Select all
`00000000`

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.
Have you ever...

Wanted to work at best companies?
Struggled with interview problems that could be solved in 15 minutes?
Wished you could study real-world problems?
If so, you need to read Elements of Programming Interviews.
DD
Experienced poster

Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California

### Re: 10929 - You can say 11

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..
qriz
New poster

Posts: 1
Joined: Sun Apr 03, 2011 5:24 pm

### Re: 10929 - You can say 11

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.
PromeNabid
New poster

Posts: 13
Joined: Mon Jun 18, 2012 12:52 am

### Re:

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.
PromeNabid
New poster

Posts: 13
Joined: Mon Jun 18, 2012 12:52 am

### Re: 10929 - You can say 11

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;}`
darksk4
New poster

Posts: 9
Joined: Sun Jul 29, 2012 7:10 pm

### Re: 10929 - You can say 11

You're missing the period at the end of each line.
brianfry713
Guru

Posts: 1765
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10929 - You can say 11

brianfry713 wrote:You're missing the period at the end of each line.

Still WA @_@
darksk4
New poster

Posts: 9
Joined: Sun Jul 29, 2012 7:10 pm

### Re: 10929 - You can say 11

100 is not a multiple of 11.
brianfry713
Guru

Posts: 1765
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10929 - You can say 11

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..
vpanait
New poster

Posts: 17
Joined: Sun Apr 01, 2012 11:01 am

### Re: 10929 - You can say 11

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.
mgavin2
New poster

Posts: 21
Joined: Sat Jul 28, 2012 6:29 pm

Previous