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

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 » Tue Jan 13, 2015 1:09 am

They mean the full integer is not 0.
For the first sample input, it's 463 + 4287
Check input and AC output for thousands of problems on uDebug!

sajib_only
New poster
Posts: 1
Joined: Sat Mar 21, 2015 12:59 am

Re: 10013 - Super long sums

Post by sajib_only » Sat Mar 21, 2015 1:02 am

//why am i continuously getting RE?? :(

//my code:

Code: Select all

#include <stdio.h>

int main()
{
    int n, m;
    int val, ex, i,j;
    scanf("%d", &n);
    while(n)
    {
        scanf("%d", &m);
        int num1[m], num2[m];
        int sum[m];
        for(i=0; i<m; i++)
        {
            scanf("%d %d", &num1[i], &num2[i]);
        }
        ex=0;
        i=m-1;
        while(i>=0)
        {
            val=num1[i]+num2[i]+ex;
            ex=0;
            if(val<10) sum[i]=val;
            else
            {
                ex++;
                sum[i]=val-10;
            }
            i--;
        }
        if(ex)
        {
            printf("%d", ex);
            for(i=0; i<m; i++) printf("%d", sum[i]);
            putchar('\n');
        }
        else
        {
            for(i=0; i<m; i++)
            {
                if(sum[i]==0) continue;
                else
                {
                    for(j=i; j<m; j++) printf("%d", sum[j]);
                    putchar('\n');
                    break;
                }
            }
        }
        n--;

        if(n) putchar('\n');
    }
    return 0;
}
Last edited by brianfry713 on Tue Mar 31, 2015 12:02 am, edited 1 time in total.
Reason: Added code block

Tiramisu
New poster
Posts: 8
Joined: Fri Feb 20, 2015 10:28 am

Re: 10013 - Super long sums

Post by Tiramisu » Thu Mar 26, 2015 7:16 am

you have to dynamically allocate memory for such large arrays, so instead of int num1[m] num2[m]
do this:
int* num1 = new int[1000000];
int* num2 = new int[1000000];
when you are done with all computation free these arrays like:
delete[] num1;
delete[] num2;

Post Reply

Return to “Volume 100 (10000-10099)”