Page 15 of 15

Re: 10013 - Super long sums

Posted: Tue Jan 13, 2015 1:09 am
by brianfry713
They mean the full integer is not 0.
For the first sample input, it's 463 + 4287

Re: 10013 - Super long sums

Posted: Sat Mar 21, 2015 1:02 am
by sajib_only
//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;
}

Re: 10013 - Super long sums

Posted: Thu Mar 26, 2015 7:16 am
by Tiramisu
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;