10013 - Super long sums

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

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

Re: 10013 - Super Long Sums

Post by brianfry713 » Fri Jun 08, 2012 10:03 pm

On the sample I/O, you are missing the newline at the end of the last line of the output.
Check input and AC output for thousands of problems on uDebug!

uvasarker
Learning poster
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Location: Dhaka, Bangladesh
Contact:

Re: 10013 - Super Long Sums

Post by uvasarker » Sat Jun 09, 2012 1:54 pm

Thanks a lot boss.
I got AC

chromeos722
New poster
Posts: 1
Joined: Sun Sep 30, 2012 12:01 pm

Re: 10013 - Super Long Sums

Post by chromeos722 » Sun Sep 30, 2012 12:11 pm

Hi,
Runtime error. Tottally don't know why. Please help.

Code: Select all

#include <stdio.h>

long a[1000001];
long b[1000001];
long sum[1000001];

int main(){

	int count;
	int digit[1000];
	digit[0] = 0;
	int size = 0;

	scanf("%d", &count);
	printf("\n");

	for(int i = 0; i < count; i++){
		scanf("%d", &digit[i+1]);
		digit[i+1] += digit[i];

		for(int j = digit[i]; j < digit[i+1]; j++){
			scanf( "%d %d", &a[j+1], &b[j+1] );
		}
		digit[i+1] += 1;
		printf("\n");
	}

	for(int i = 0; i < count; i++){
		int j = digit[i+1]-1;
		int temp;
		do 
		{
			if(sum[j+1] == 10){
				sum[j+1] = 0;
				sum[j] += 1;
			}

			if( a[j] + b[j] >= 10 ){
				temp = (a[j] + b[j]) % 10;
				sum[j] += temp;
				sum[j -1] = 1;
			}

			else{
				sum[j] += a[j] + b[j];
			}

			j--;
		}while (j != digit[i]);
	}

	for(int i = 0; i < count; i++){
		for(int j = digit[i]; j <digit[i+1]; j++){
			if(j == digit[i] && sum[j] == 0){
				j++;
			}
			printf("%d", sum[j]);
		}
		if(i != count - 1){
			printf("\n\n");
		}
		else{
			printf("\n");
		}
	}

	return 0;
}

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

Re: 10013 - Super Long Sums

Post by brianfry713 » Mon Oct 01, 2012 9:43 pm

Print the results for each test case right away, don't try and store all the results.
Check input and AC output for thousands of problems on uDebug!

sonjbond
New poster
Posts: 19
Joined: Wed Jul 04, 2012 10:30 pm

Re: 10013 - Super Long Sums(WA Y??)

Post by sonjbond » Sun Oct 21, 2012 12:35 pm

why i am getting WA ?? plz help me .....
my code is here :

Code: Select all

#include<stdio.h>
#include<string.h>
int num1[1000010],num2[1000010],sum[1000015];
int main()
{
    long tc;
    scanf("%ld",&tc);
    while(tc--)
    {
        //printf("\n");
        long i,j,k,m,n,rem;
        scanf("%ld",&n);
        for(i=0; i<n; i++)
            scanf("%d %d",&num1[i],&num2[i]);
        rem=0;
        for(i=n-1; i>=0; i--)
        {
            m=num1[i]+num2[i]+rem;
            sum[i]=m%10;
            rem=m/10;
        }
        /*if(rem!=0)
        {
            printf("%ld",rem);
        }*/
        for(i=0; i<n; i++)
            printf("%d",sum[i]);
        if(tc)printf("\n");

    }
    return 0;
}

plz help meeeeeeeeee :( :( :( :( :( :( :( :( :( :(

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

Re: 10013 - Super Long Sums

Post by brianfry713 » Tue Oct 23, 2012 10:34 pm

There is a blank line between output blocks.
Check input and AC output for thousands of problems on uDebug!

naim
New poster
Posts: 3
Joined: Fri Jan 11, 2013 10:46 am

10013 - Super long sums,i got it WA more time

Post by naim » Fri Jan 11, 2013 11:13 am

#include<stdio.h>
#include<string.h>
int a[1000001],b[1000001],sum1[1000001];
int main()
{

long int t,m,i,j,sum;
scanf("%ld",&t);
for(i=0;i<t;i++)
{
scanf("%ld",&m);
for(j=0;j<m;j++)
scanf("%d %d",&a[j],&b[j]);
sum=0;
for(j=m-1;j>=0;j--)
{
sum=a[j]+b[j]+sum;
sum1[j]=sum%10;
sum=sum/10;
}
for(j=0;j<m;j++)
{
printf("%d",sum1[j]);

}
printf("\n\n");
}
return 0;
}
:(

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

Re: 10013 - Super long sums,i got it WA more time

Post by brianfry713 » Fri Jan 11, 2013 8:35 pm

There is a blank line between output blocks.
Don't print a blank line after the last output.
Check input and AC output for thousands of problems on uDebug!

naim
New poster
Posts: 3
Joined: Fri Jan 11, 2013 10:46 am

10013- Super long sums-again & again WA plz help...

Post by naim » Mon Jan 14, 2013 6:45 pm

#include<stdio.h>
#include<string.h>
int a[1000001],b[1000001],sum1[1000001];
int main()
{

long int t,m,i,j,sum;
scanf("%ld",&t);
printf("\n");
for(i=0;i<t;i++)
{
scanf("%ld",&m);
for(j=0;j<m;j++)
scanf("%d %d",&a[j],&b[j]);
sum=0;
for(j=m-1;j>=0;j--)
{
sum=a[j]+b[j]+sum;
sum1[j]=sum%10;
sum=sum/10;
}
for(j=0;j<m;j++)
{
printf("%d",sum1[j]);

}
if(i==0)
printf("\n");
}
return 0;
}
:oops:

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

Re: 10013- Super long sums-again & again WA plz help...

Post by brianfry713 » Mon Jan 14, 2013 9:46 pm

For the sample input you're printing "\n4750\n470". It should be "4750\n\n470\n"
Check input and AC output for thousands of problems on uDebug!

User avatar
shaon_cse_cu08
New poster
Posts: 50
Joined: Tue May 25, 2010 9:10 am
Contact:

Re: 10013 - Super Long Sums

Post by shaon_cse_cu08 » Sat May 25, 2013 6:29 pm

Hello.. plzzz Help.. I don't know But every times i m submitting i m getting Submission Error... :x
I don't knw whats the problem... and for my entire UVa lifetime i hv never got an Submission Error (What is this!!)...
Its Driving me creazy... :oops: PLZ Help!!!

Code: Select all

import java.math.BigInteger;
import java.util.Scanner;


public class Main
{
    public static void main(String args[])
    {
        Scanner inp = new Scanner(System.in);
        
        long n,m,x,y,i;
        
        n = inp.nextLong();
        
        while(n>0)
        {
            String a = new String();
            String b = new String();
           
            m = inp.nextLong();
            
            for(i =0; i<m; i++)
            {
                x = inp.nextLong();
                y = inp.nextLong();
                
                a += ""+x;
                b += ""+y;
            }
            
            BigInteger aa = new BigInteger(a);
            BigInteger bb = new BigInteger(b);
            
            System.out.println(aa.add(bb));
            
            
            n--;
            
            if(n>0)
                System.out.println();
        }
         
    }
}
I'll keep holding on...Until the walls come tumbling down...And freedom is all around ..... :x

User avatar
shaon_cse_cu08
New poster
Posts: 50
Joined: Tue May 25, 2010 9:10 am
Contact:

10013 - Super Long Sum (Submission Error!!!)

Post by shaon_cse_cu08 » Mon May 27, 2013 12:14 pm

Hello.. plzzz Help.. I don't know But every time i m submitting i m getting Submission Error... :x
I don't knw whats the problem... and for my entire UVa lifetime i hv never got an Submission Error (What is this!!)...
Its Driving me creazy... :oops: PLZ Help!!!

Code: Select all

import java.math.BigInteger;
import java.util.Scanner;


public class Main
{
    public static void main(String args[])
    {
        Scanner inp = new Scanner(System.in);
        
        long n,m,x,y,i;
        
        n = inp.nextLong();
        
        while(n>0)
        {
            String a = new String();
            String b = new String();
           
            m = inp.nextLong();
            
            for(i =0; i<m; i++)
            {
                x = inp.nextLong();
                y = inp.nextLong();
                
                a += ""+x;
                b += ""+y;
            }
            
            BigInteger aa = new BigInteger(a);
            BigInteger bb = new BigInteger(b);
            
            System.out.println(aa.add(bb));
            
            
            n--;
            
            if(n>0)
                System.out.println();
        }
         
    }
}
I'll keep holding on...Until the walls come tumbling down...And freedom is all around ..... :x

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

Re: 10013 - Super Long Sum (Submission Error!!!)

Post by brianfry713 » Tue May 28, 2013 11:47 pm

There are a lot of submission errors lately. Try a different problem for now.
Check input and AC output for thousands of problems on uDebug!

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

Re: 10013 - Super Long Sums

Post by brianfry713 » Tue May 28, 2013 11:49 pm

There are a lot of submission errors lately. Try a different problem for now.
Check input and AC output for thousands of problems on uDebug!

techbd123
New poster
Posts: 14
Joined: Tue Aug 06, 2013 3:42 pm

Re: 10013 - Super Long Sums

Post by techbd123 » Sat Nov 09, 2013 3:52 am

Please help Guru Brainfry! Why getting WA?

Code: Select all

#include <stdio.h>

short int sum[1000001],crry[1000001];
unsigned char numstr[1000001];

int main()
{
    int i,t,n,c,f=0;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        i=n;
        while(i--)
        {
            scanf("%d",&c);sum[i]=c;scanf("%d",&c);sum[i]+=c;
            if(sum[i]>9){sum[i]-=10;crry[i]=1;}
            else crry[i]=0;
        }
        for(i=0;i<n;i++)
        {
            if(i>0) sum[i]+=crry[i-1];
            if(sum[i]>9)
            {
                sum[i]-=10;
                crry[i]++;
            }
            numstr[n-i-1]=sum[i]+48;
        }
        numstr[i]=0;
        if(f) printf("\n%s\n",numstr);
        else {printf("%s",numstr);f=1;}
    }
    return 0;
}

Post Reply

Return to “Volume 100 (10000-10099)”