UVa 10013 Super Long sums: simple high precision

Source: Internet
Author: User
Tags time limit

10013-super Long sums

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=954

The Problem

The creators of a new programming language d++ have found out which whatever limit for superlongint type they to make, Sometim ES programmers need to operate even larger numbers. A limit of 1000 digits is so small ... You are have to find the sum of two numbers with maximal size of 1.000.000 digits.

The Input

The the ' a ' input file is an integer N, then a blank line followed by n input blocks. The "a" each input blocks contains a single number M (1<=m<=1000000)-the length of the integers (in or Der to make their lengths equal, some leading zeroes can be added). It is followed by this integers written in columns. That's, the next M lines contain two digits each and divided by a. Each of the two given integers isn't less than 1, and the length of their sum does not exceed M.

There is a blank line between input blocks.

The Output

Each output block should contain exactly M digits into a single line representing the sum of this two integers.

There is a blank line between output blocks.

Sample Input

240 44 26 83 733 07 92 8

Sample Output

4750470

Complete code:

/*0.915s*/
    
#include <cstdio>  
    
int a[1000010], b[1000010], c[1000010];  
    
int main ()  
{  
    int t, M, I, K, carry;  
    scanf ("%d", &t);  
    while (t--)  
    {  
        scanf ("%d", &m);  
        for (i = 0; i < M ++i)  
            scanf ("%d%d", &a[i), &b[i]);  
        carry = 0;  
        for (i = M-1 i >= 0;-I.)  
        {  
            k = carry + A[i] + b[i];  
            Carry = k > 9? 1:0;  
            C[i] = k%;  
        }  
        for (i = 0; i < M i++)  
            printf ("%d", C[i]);  
        Putchar (ten);  
        if (t) Putchar (a);  
    }  
    return 0;  
}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.