Page 12 of 15
Re: 10013 - Super Long Sums
Posted: Tue Apr 07, 2009 1:30 pm
by Obaida
I didn't checked your code. But i think large size array Declaration should be done globally.
Otherwise it will cause Runtime Error.
Re: 10013 - Super Long Sums
Posted: Thu Aug 06, 2009 12:27 pm
by Jordi Aranda
Hi guys, I don't know what's wrong with my code. I've tried all inputs in this thread and I pass all them. Maybe I haven't understood well the problem (my English is not good enough

)
Thx in advance
Re: 10013 - Super Long Sums
Posted: Thu Aug 06, 2009 5:33 pm
by mf
UVa judge is sensitive to blank lines, and, unfortunately, conventions about blank lines are different in different problems. Some problems ask you to print a blank line after the output for each test cases. But other problems (like this one) ask to print a blank line
between test cases, that is you shouldn't output a blank line after the last test case.
(But if you ever get to ICPC finals, don't worry - they don't care about silly stuff like that, and either version of the output is OK)
Also, you can make the main loop of your bignum addition procedure much shorter if you make carry an integer variable, see:
Code: Select all
int carry = 0;
for (int i = 0; i < n; i++) {
carry += (a[n-1-i] - '0') + (b[n-1-i] - '0');
result += carry % 10 + '0';
carry /= 10;
}
Re: 10013 - Super Long Sums
Posted: Thu Aug 06, 2009 11:27 pm
by Jordi Aranda
Thank you very much for the explanation and you're right with the loop, my function was a real mess

10013 - Super Long Sums
Posted: Sun Aug 08, 2010 11:48 pm
by sayem
@ sazzadcsedu thanks
get ACC
10013 why WA
Posted: Sat Aug 14, 2010 11:21 am
by @mjad
I got ACC
thanx for reply
Re: 10013 - Super Long Sums
Posted: Mon Aug 23, 2010 7:09 pm
by sazzadcsedu
To @majad:
There is a blank line between output blocks.
You code does not obey it.So you got WA.just add a blank line between cases and get Acc.
To @sayem:
You did the
same mistake.Here is your modified code-
Code: Select all
#include<stdio.h>
#include<stdlib.h>
int main()
{
int N,Case=1;
//freopen("input.txt","r",stdin);
//freopen("output1.txt","w",stdout);
if(scanf("%d",&N)==1)
{
for(int in=0;in<N;in++)
{
long M;
if(scanf("%ld",&M)==1)
{
long *sum=new long[M+1];
long *up=new long [M+1];
long *down=new long [M+1];
long im;
for(im=0;im<M;im++)
{
long a,b;
if(scanf("%ld%ld",&a,&b)==2)
{
up[im]=a;
down[im]=b;
}
else exit(0);
}
long carry=0;
long i=0;
for(im=M-1;im>=0;im--)
{
sum[i]=(up[im]+down[im]+carry)%10;
carry=(up[im]+down[im]+carry)/10;
i++;
}
if(Case>1)
printf("\n");
for(im=M-1;im>=0;im--)
printf("%ld",sum[im]);
printf("\n");
delete[] sum;
delete[] up;
delete[] down;
}
else exit(0);
Case++;
}
}
return 0;
}
Submit it and get Acc. And inform me so that i can delete it.
Good luck.
Re: 10013 - Super Long Sums
Posted: Tue Sep 14, 2010 8:44 pm
by sheik_08
Why im getting WA??
Code: Select all
#include <stdio.h>
#include <string.h>
int n,m,v[1000100],w[1000100];
int main(){
//freopen("Entrada.in","r",stdin);
//freopen("Salida.out","w",stdout);
scanf("%d",&m);
int j;
for(j=0;j<m;j++){
//memset(v,0,sizeof(v));
//memset(w,0,sizeof(w));
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d %d",&v[i],&w[i]);
}
int k;
int u=n;
while(n>1){
k = v[n] + w[n];
if(k>=10){
v[n-1]++;
v[n] = k%10;
}
else v[n]=k;
n--;
}
k = v[n] + w[n];
v[n]=k;
for(int i=1;i<=u;i++){
printf("%d",v[i]);
}
if(j!=m-1) printf("\n\n");
}
return 0;
}
please answer.
Re: 10013 - Super Long Sums (WA)
Posted: Fri Oct 01, 2010 3:53 am
by fkrafi
Re: 10013 - Super Long Sums (WHY WA)
Posted: Wed Oct 06, 2010 7:56 pm
by fkrafi
solved....
Re: 10013 - Super Long Sums
Posted: Wed May 11, 2011 2:58 pm
by valkov
Just got AC for this one.
I used 3 arrays one for the first number, one for the second and one for the result. Each one of them had 1000003 elements.
Using simple addition algorithm with I/O using scanf/printf(C++ code) I got AC in under 1 sec. So don't bother if you are not speed junkie

Re: 10013 - Super Long Sums
Posted: Mon Mar 26, 2012 2:36 pm
by rambo1980
I'm just dumbstruck, i've tried at least 30 different testcases of different types, my program seems to work perfectly, but judge gives me
WA
Anybody, please help me out, where am i going wrong??
Re: 10013 - Super Long Sums
Posted: Tue Mar 27, 2012 11:52 pm
by brianfry713
There is a blank line between output blocks. Don't print a newline after the last output.
Re: 10013 - Super Long Sums
Posted: Wed Mar 28, 2012 10:51 pm
by rambo1980
thanks, i've recently heard abt these problems, kind of weird,,anyway got AC now, thanks again and again brainfry

Re: 10013 - Super Long Sums
Posted: Fri Jun 08, 2012 8:57 am
by uvasarker
Please help me Why I am getting W A continuously........