• HDU-1002


    A + B Problem II

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 287467    Accepted Submission(s): 55255


    Problem Description
    I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
     
    Input
    The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
     
    Output
    For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.
     
    Sample Input
    2 1 2 112233445566778899 998877665544332211
     
    Sample Output
    Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110
    #include<stdio.h>
    #include<string.h>
    int main()
    {
        int n,j;
        scanf("%d",&n);
        for(j=0;j<n;j++)
        {
            int a[1200]={0},b[1200]={0},c[1200]={0},i,long1,long2,k;
            char a1[1200],b1[1200];
            scanf("%s",a1);
            scanf("%s",b1);
            long1=strlen(a1);
            long2=strlen(b1);
            for(i=0;i<long1;i++)
                a[i]=a1[long1-i-1]-'0';
            for(i=0;i<long2;i++)
                b[i]=b1[long2-i-1]-'0';
                
              k=long1<long2?long2:long1;
            for(i=0;i<k;i++)
                c[i]=a[i]+b[i];
            for(i=0;i<k;i++)
                if(c[i]>=10)
                {
                    c[i+1]+=c[i]/10;
                    c[i]%=10;
                }
                printf("Case %d:
    ",j+1);
                printf("%s + %s = ",a1,b1);
                if(c[k]==0)
                    k--;
                for(i=k;i>=0;i--)
                    printf("%d",c[i]);
                if(j==n-1)
                    printf("
    ");
                else
                    printf("
    
    ");
        }
        return 0;
    }
  • 相关阅读:
    32-Ubuntu-用户权限-03-修改文件权限
    31-Ubuntu-用户权限-02-ls输出信息介绍
    hdu2084 数塔
    hdu 1058 humble number
    HDU_2050 折线分割平面
    HDU_1030 Delta-wave 常数时间
    HDU_1021 Fibonacci Again 一些推论
    Gated Recurrent Unit(GRU)
    循环神经网络模型
    Bellman-Ford algorithm
  • 原文地址:https://www.cnblogs.com/tt-t/p/5073836.html
Copyright © 2020-2023  润新知