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

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10013 - Super Long Sums

Post 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.
try_try_try_try_&&&_try@try.com
This may be the address of success.
Jordi Aranda
New poster
Posts: 13
Joined: Wed Apr 29, 2009 11:37 am
Location: Barcelona

Re: 10013 - Super Long Sums

Post 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 :lol: )

Code: Select all

Removed after accepted
Thx in advance
Last edited by Jordi Aranda on Thu Aug 06, 2009 11:32 pm, edited 2 times in total.
Born to be wild
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 10013 - Super Long Sums

Post 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;
    }
Jordi Aranda
New poster
Posts: 13
Joined: Wed Apr 29, 2009 11:37 am
Location: Barcelona

Re: 10013 - Super Long Sums

Post by Jordi Aranda »

Thank you very much for the explanation and you're right with the loop, my function was a real mess :roll:
Born to be wild
sayem
New poster
Posts: 7
Joined: Sun Jul 12, 2009 10:30 pm

10013 - Super Long Sums

Post by sayem »

@ sazzadcsedu thanks
get ACC
Last edited by sayem on Wed Aug 25, 2010 2:50 pm, edited 1 time in total.
@mjad
New poster
Posts: 44
Joined: Thu Jul 22, 2010 9:42 am

10013 why WA

Post by @mjad »

:D

I got ACC
thanx for reply
Last edited by @mjad on Mon Oct 11, 2010 4:04 am, edited 1 time in total.
sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: 10013 - Super Long Sums

Post 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.
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
sheik_08
New poster
Posts: 1
Joined: Tue Sep 14, 2010 8:42 pm

Re: 10013 - Super Long Sums

Post 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.
fkrafi
New poster
Posts: 13
Joined: Wed Sep 15, 2010 1:36 pm

Re: 10013 - Super Long Sums (WA)

Post by fkrafi »

Why WA

Code: Select all

Solved
Last edited by fkrafi on Tue Mar 01, 2011 2:47 pm, edited 1 time in total.
fkrafi
New poster
Posts: 13
Joined: Wed Sep 15, 2010 1:36 pm

Re: 10013 - Super Long Sums (WHY WA)

Post by fkrafi »

solved....
Last edited by fkrafi on Wed Jun 01, 2011 9:31 pm, edited 1 time in total.
valkov
New poster
Posts: 20
Joined: Tue Jul 20, 2010 3:11 pm

Re: 10013 - Super Long Sums

Post 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 :)
rambo1980
New poster
Posts: 15
Joined: Sun Mar 18, 2012 2:45 pm

Re: 10013 - Super Long Sums

Post 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

Code: Select all

 REMOVED AFTER AC 
Anybody, please help me out, where am i going wrong??
Last edited by rambo1980 on Wed Mar 28, 2012 10:51 pm, edited 1 time in total.
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 »

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!
rambo1980
New poster
Posts: 15
Joined: Sun Mar 18, 2012 2:45 pm

Re: 10013 - Super Long Sums

Post by rambo1980 »

thanks, i've recently heard abt these problems, kind of weird,,anyway got AC now, thanks again and again brainfry :D
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 »

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

Return to “Volume 100 (10000-10099)”