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

turcse143
Learning poster
Posts: 81
Joined: Wed May 09, 2007 9:59 pm
Location: (CSE,DU) Dhaka,Bangladesh

Post by turcse143 » Thu Feb 28, 2008 6:07 pm

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

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Ok.....

Post by Obaida » Fri Feb 29, 2008 6:42 am

Thankx brother..... Decoded it. 8)
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
Location: (BUBT) Dhaka,Bagladesh.

Re: Ok.....

Post by Obaida » Fri Feb 29, 2008 8:13 am

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..... 8)
try_try_try_try_&&&_try@try.com
This may be the address of success.

turcse143
Learning poster
Posts: 81
Joined: Wed May 09, 2007 9:59 pm
Location: (CSE,DU) Dhaka,Bangladesh

Post by turcse143 » Fri Feb 29, 2008 7:25 pm

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

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

Re: 10929 - You can say 11

Post by naseefcuet » Mon Jul 20, 2009 7:05 am

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

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

Re:

Post by DD » Mon Mar 14, 2011 12:09 am

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.

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

Re: 10929 - You can say 11

Post by qriz » Sun Apr 03, 2011 5:30 pm

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

PromeNabid
New poster
Posts: 21
Joined: Mon Jun 18, 2012 12:52 am
Location: Dhaka, Bangladesh.
Contact:

Re: 10929 - You can say 11

Post by PromeNabid » Mon Jun 18, 2012 1:08 am

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: 21
Joined: Mon Jun 18, 2012 12:52 am
Location: Dhaka, Bangladesh.
Contact:

Re:

Post by PromeNabid » Mon Jun 18, 2012 1:09 am

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.

darksk4
New poster
Posts: 13
Joined: Sun Jul 29, 2012 7:10 pm

Re: 10929 - You can say 11

Post by darksk4 » Sun Sep 23, 2012 11:10 am

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;
}


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

Re: 10929 - You can say 11

Post by brianfry713 » Tue Sep 25, 2012 1:51 am

You're missing the period at the end of each line.
Check input and AC output for thousands of problems on uDebug!

darksk4
New poster
Posts: 13
Joined: Sun Jul 29, 2012 7:10 pm

Re: 10929 - You can say 11

Post by darksk4 » Tue Sep 25, 2012 4:39 am

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

Still WA @_@

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

Re: 10929 - You can say 11

Post by brianfry713 » Tue Sep 25, 2012 10:09 pm

100 is not a multiple of 11.
Check input and AC output for thousands of problems on uDebug!

vpanait
New poster
Posts: 17
Joined: Sun Apr 01, 2012 11:01 am

Re: 10929 - You can say 11

Post by vpanait » Fri Oct 05, 2012 10:12 am

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

mgavin2
New poster
Posts: 43
Joined: Sat Jul 28, 2012 6:29 pm

Re: 10929 - You can say 11

Post by mgavin2 » Thu Oct 18, 2012 8:15 pm

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 :lol:

OMFG :evil:
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.
all that matters is AC

Post Reply

Return to “Volume 109 (10900-10999)”