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

Faithkeeper_Rangwan
New poster
Posts: 12
Joined: Sun Jul 07, 2013 7:32 pm

Re: 10929 - You can say 11

Post by Faithkeeper_Rangwan »

Code: Select all

import java.util.*;
import java.math.*;
class Main 
{
	public static void main(String[] args)
	{
		BigInteger a,b;
		Scanner sc = new Scanner(System.in);
		a = sc.nextBigInteger();
		while(!a.equals(BigInteger.ZERO))
		{
			b =a.mod(BigInteger.valueOf(11));
			if(b.equals(BigInteger.ZERO)) System.out.println(a+" is a multiple of 11.");
			else System.out.println(a+" is not a multiple of 11.");
			a = sc.nextBigInteger();
		}
	}
}
Also got WA with this one, don't know how to fix this :(

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 »

input:

Code: Select all

01
0
output should be

Code: Select all

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

Faithkeeper_Rangwan
New poster
Posts: 12
Joined: Sun Jul 07, 2013 7:32 pm

Re: 10929 - You can say 11

Post by Faithkeeper_Rangwan »

brianfry713 wrote:input:

Code: Select all

01
0
output should be

Code: Select all

01 is not a multiple of 11.
AC'd

Thanks.

woaraka92
New poster
Posts: 9
Joined: Sun Oct 20, 2013 6:50 pm

UVA 10929

Post by woaraka92 »

#include<stdio.h>
#include<string.h>

int main(){
char a[1002];
int i,sum;
while(1){
scanf("%s",a);
if(strcmp(a,"0")==0)
break;

sum=0;
for(i=0;a!='\0';i++){
sum=sum*10+a-48;
if(sum<11){
i++;
sum=sum*10+a-48;
}

if(sum>10)
sum=sum%11;
}

if(sum==0)
printf("%s is a multiple of 11.\n",a);
else
printf("%s is not a multiple of 11.\n",a);

}
return 0;
}

woaraka92
New poster
Posts: 9
Joined: Sun Oct 20, 2013 6:50 pm

Re: UVA 10929

Post by woaraka92 »

whats the problem in this code?

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

Re: UVA 10929

Post by brianfry713 »

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

woaraka92
New poster
Posts: 9
Joined: Sun Oct 20, 2013 6:50 pm

Re: UVA 10929

Post by woaraka92 »

Thanks brianfry713..

jddantes
Learning poster
Posts: 73
Joined: Sat Mar 08, 2014 8:55 am

Re: 10929 - You can say 11

Post by jddantes »

What's wrong with mine?
Also by positive number do they mean positive integers?

Code: Select all

#include <stdio.h>
#include <string.h>
int main()
{
    char number[1005];
    while(fgets(number, 1005, stdin)!=NULL)
    {
        number[strlen(number)-1] = 0;

        if(number[0] == '0' && number[1] == 0)
        {
            return 0;
        }

        int sum = 0;
        int i = 0;
        for(i=0; number[i];i++)
        {

            if(i%2 == 0)
            {
                sum+=number[i] - '0';
            }
            else
            {
                sum-=number[i] - '0';
            }

            //printf("%d %d\n",sum, number[i] - '0');
        }

        if (sum % 11 == 0)
        {
            printf("%s is a multiple of 11.\n",number);
        }
        else
        {
            printf("%s is not a multiple of 11.\n",number);
        }
    }

    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 »

That is AC code.
Yes they mean positive integers.
Check input and AC output for thousands of problems on uDebug!

jddantes
Learning poster
Posts: 73
Joined: Sat Mar 08, 2014 8:55 am

Re: 10929 - You can say 11

Post by jddantes »

Why is mine WA?

Code: Select all

#include <stdio.h>
#include <string.h>
int main()
{
    char number[1005];
    while(fgets(number, 1005, stdin)!=NULL)
    {
        number[strlen(number)-1] = 0;

        if(number[0] == '0' && number[1] == 0)
        {
            return 0;
        }

        int sum = 0;
        int i = 0;
        for(i=0; number[i];i++)
        {

            if(i%2 == 0)
            {
                sum+=number[i] - '0';
            }
            else
            {
                sum-=number[i] - '0';
            }

            //printf("%d %d\n",sum, number[i] - '0');
        }

        if (sum % 11 == 0)
        {
            printf("%s is a multiple of 11.\n",number);
        }
        else
        {
            printf("%s is not a multiple of 11.\n",number);
        }
    }

    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 »

That is AC code.
Check input and AC output for thousands of problems on uDebug!

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 10929 - You can say 11

Post by uDebug »

So, for this problem, it turns out that there are two outputs that are both accepted.

For, the following input

Code: Select all

            112233              
    00000000030800
   2937                           
                      323455693                 
          5038297          
          00000112234     
00112            
0
AC Output #1:

Code: Select all

112233 is a multiple of 11.
00000000030800 is a multiple of 11.
2937 is a multiple of 11.
323455693 is a multiple of 11.
5038297 is a multiple of 11.
00000112234 is not a multiple of 11.
00112 is not a multiple of 11.
AC Output #2:

Code: Select all

            112233               is a multiple of 11.
    00000000030800 is a multiple of 11.
   2937                            is a multiple of 11.
                      323455693                  is not a multiple of 11.
          5038297           is a multiple of 11.
          00000112234      is not a multiple of 11.
00112             is not a multiple of 11.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

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 »

There probably aren't spaces in the judge's input.
Check input and AC output for thousands of problems on uDebug!

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 10929 - You can say 11

Post by uDebug »

brianfry713 wrote:There probably aren't spaces in the judge's input.
That makes sense. Thanks.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

jddantes
Learning poster
Posts: 73
Joined: Sat Mar 08, 2014 8:55 am

Re: 10929 - You can say 11

Post by jddantes »

Why is mine not accepted?

Code: Select all

#include <stdio.h>
#include <string.h>
int main()
{
    char number[1005];
    while(fgets(number, 1005, stdin)!=NULL)
    {
        number[strlen(number)-1] = 0;

        if(number[0] == '0' && number[1] == 0)
        {
            return 0;
        }

        int sum = 0;
        int i = 0;
        for(i=0; number[i];i++)
        {

            if(i%2 == 0)
            {
                sum+=number[i] - '0';
            }
            else
            {
                sum-=number[i] - '0';
            }

            //printf("%d %d\n",sum, number[i] - '0');
        }

        if (sum % 11 == 0)
        {
            printf("%s is a multiple of 11.\n",number);
        }
        else
        {
            printf("%s is not a multiple of 11.\n",number);
        }
    }

    return 0;
}


Post Reply

Return to “Volume 109 (10900-10999)”