10013 - Super long sums
Moderator: Board moderators
Re: 10013 - Super Long Sums
I didn't checked your code. But i think large size array Declaration should be done globally.
Otherwise it will cause Runtime Error.
Otherwise it will cause Runtime Error.
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
-
- New poster
- Posts: 13
- Joined: Wed Apr 29, 2009 11:37 am
- Location: Barcelona
Re: 10013 - Super Long Sums
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
Code: Select all
Removed after accepted
Last edited by Jordi Aranda on Thu Aug 06, 2009 11:32 pm, edited 2 times in total.
Born to be wild
Re: 10013 - Super Long Sums
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:
(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;
}
-
- New poster
- Posts: 13
- Joined: Wed Apr 29, 2009 11:37 am
- Location: Barcelona
Re: 10013 - Super Long Sums
Thank you very much for the explanation and you're right with the loop, my function was a real mess
Born to be wild
10013 - Super Long Sums
@ sazzadcsedu thanks
get ACC
get ACC
Last edited by sayem on Wed Aug 25, 2010 2:50 pm, edited 1 time in total.
10013 why WA
I got ACC
thanx for reply
Last edited by @mjad on Mon Oct 11, 2010 4:04 am, edited 1 time in total.
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
Re: 10013 - Super Long Sums
To @majad:
To @sayem:
You did the same mistake.Here is your modified code-
Submit it and get Acc. And inform me so that i can delete it.
Good luck.
You code does not obey it.So you got WA.just add a blank line between cases and get Acc.There is a blank line between output blocks.
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;
}
Good luck.
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
Re: 10013 - Super Long Sums
Why im getting WA??
please answer.
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;
}
Re: 10013 - Super Long Sums (WA)
Why WA
Code: Select all
Solved
Last edited by fkrafi on Tue Mar 01, 2011 2:47 pm, edited 1 time in total.
Re: 10013 - Super Long Sums (WHY WA)
solved....
Last edited by fkrafi on Wed Jun 01, 2011 9:31 pm, edited 1 time in total.
Re: 10013 - Super Long Sums
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
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
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??
Code: Select all
REMOVED AFTER AC
Last edited by rambo1980 on Wed Mar 28, 2012 10:51 pm, edited 1 time in total.
-
- 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. Don't print a newline after the last output.
Check input and AC output for thousands of problems on uDebug!
Re: 10013 - Super Long Sums
thanks, i've recently heard abt these problems, kind of weird,,anyway got AC now, thanks again and again brainfry
-
- Learning poster
- Posts: 96
- Joined: Tue Jul 19, 2011 12:19 pm
- Location: Dhaka, Bangladesh
- Contact:
Re: 10013 - Super Long Sums
Please help me Why I am getting W A continuously........
Code: Select all
AC
Last edited by uvasarker on Mon Jun 11, 2012 8:29 pm, edited 1 time in total.