## 10013 - Super long sums

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

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

### Re: 10013 - Super Long Sums

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

Hi,

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

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??)

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

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

#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

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

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

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!
shaon_cse_cu08
New poster
Posts: 50
Joined: Tue May 25, 2010 9:10 am
Contact:

### Re: 10013 - Super Long Sums

Hello.. plzzz Help.. I don't know But every times i m submitting i m getting Submission Error...
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... 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);

n--;

if(n>0)
System.out.println();
}

}
}
``````
I'll keep holding on...Until the walls come tumbling down...And freedom is all around .....
shaon_cse_cu08
New poster
Posts: 50
Joined: Tue May 25, 2010 9:10 am
Contact:

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

Hello.. plzzz Help.. I don't know But every time i m submitting i m getting Submission Error...
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... 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);

n--;

if(n>0)
System.out.println();
}

}
}
``````
I'll keep holding on...Until the walls come tumbling down...And freedom is all around .....
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

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

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

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

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