10013 - Super long sums
Moderator: Board moderators
-
- 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!
-
- Learning poster
- Posts: 96
- Joined: Tue Jul 19, 2011 12:19 pm
- Location: Dhaka, Bangladesh
- Contact:
Re: 10013 - Super Long Sums
Thanks a lot boss.
I got AC
I got AC
-
- New poster
- Posts: 1
- Joined: Sun Sep 30, 2012 12:01 pm
Re: 10013 - Super Long Sums
Hi,
Runtime error. Tottally don't know why. Please help.
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;
}
-
- 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!
Re: 10013 - Super Long Sums(WA Y??)
why i am getting WA ?? plz help me .....
my code is here :
plz help meeeeeeeeee
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;
}
-
- 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!
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;
}
#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;
}
-
- 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.
Don't print a blank line after the last output.
Check input and AC output for thousands of problems on uDebug!
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;
}
#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;
}
-
- 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!
-
- 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!!!
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);
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 .....
-
- 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!!!
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);
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 .....
-
- 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!
-
- 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!
Re: 10013 - Super Long Sums
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;
}