zoukankan      html  css  js  c++  java
  • HDUOJ1002A + B Problem II

    A + B Problem II

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


    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
     
     
    View Code
     1 #include<stdio.h>
     2 #include<string.h>
     3 #define maxn 1010
     4 int shu1[maxn],shu2[maxn];
     5 char str1[maxn],str2[maxn];
     6 int main()
     7 {
     8     int n,i,j,len1,len2,k;
     9     scanf("%d",&n);
    10     getchar();
    11     for(k=1;k<=n;k++)
    12     {
    13         scanf("%s",str1);
    14         scanf("%s",str2);
    15         printf("Case %d:\n%s + %s = ",k,str1,str2);
    16         memset(shu1,0,sizeof(shu1));
    17         memset(shu2,0,sizeof(shu2));
    18         len1=strlen(str1);
    19         len2=strlen(str2);
    20         //printf("lenstr1=%d,lenstr2=%d",len1,len2);//
    21         for(j=0,i=len1-1;i>=0;i--)
    22             shu1[j++]=str1[i]-'0';
    23         for(j=0,i=len2-1;i>=0;i--)
    24             shu2[j++]=str2[i]-'0';
    25         for(i=0;i<maxn;i++)
    26         {
    27             shu1[i]+=shu2[i];
    28             if(shu1[i]>=10)
    29             {
    30                 shu1[i]%=10;
    31                 shu1[i+1]++;
    32             }
    33         }
    34     //for(i=0;i<maxn;i++)
    35         //printf("%d",shu1[i]);//
    36        for(j=maxn-1;j>=0;j--)
    37           if(shu1[j])break;
    38        if(j==-1)
    39            printf("0");
    40        else 
    41         {
    42             for(i=j;i>=0;i--)
    43            printf("%d",shu1[i]);
    44         }
    45      if(k<n)
    46      printf("\n\n");
    47      else
    48      printf("\n");
    49     }
    50 return 0;
    51 }
  • 相关阅读:
    Maven项目Spring配置XML报错
    Emcas配置快捷代码块
    ubuntu安装ipython
    基于Docker的集成开发环境包含gvim&Emacs
    deepin安装v11vnc服务
    Eclipse 默认工作区设置
    docker方式搭建DNS服务器
    deepin安装vnc服务
    DataReader类型化数据读取与装箱性能研究
    评《禁止分班考试惹争议:学霸吃不饱,学渣吃不消》:营造公平社会环境从不分班开始
  • 原文地址:https://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_2012_07_26000.html
Copyright © 2011-2022 走看看