zoukankan      html  css  js  c++  java
  • 杭电ACM1002

    原题:http://acm.hdu.edu.cn/showproblem.php?pid=1002

     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 int main()
     5 {
     6     int T,num=0,i,len,len1,len2;
     7     char str1[1001],str2[1001];
     8     scanf("%d",&T);
     9     while(T--)
    10     {
    11         int  a[1001]={0},b[1001]={0},c[1001]={0},k=0;
    12         scanf("%s",str1);
    13         scanf("%s",str2);
    14         len1=strlen(str1);
    15         len2=strlen(str2);
    16         len=(len1>len2)?len1:len2;
    17         for(i=0;i<=len1-1;++i)
    18             a[i]=str1[len1-1-i]-'0';
    19         for(i=0;i<=len2-1;++i)
    20             b[i]=str2[len2-1-i]-'0';
    21         for(i=0;i<=len-1;++i)
    22         {
    23             c[i]=(a[i]+b[i]+k)%10;
    24             k=(a[i]+b[i]+k)/10;
    25         }
    26         printf("Case %d:
    ",++num);
    27         printf("%s + %s = ",str1,str2);
    28         if(k)
    29             printf("1");
    30         for(i=len-1;i>=0;--i)
    31             printf("%d",c[i]);
    32         printf("
    ");
    33         if(T >= 1)
    34             printf("
    ");
    35     }
    36     return 0;
    37 }

    需要注意的只是显示空行。

  • 相关阅读:
    cf854B Maxim Buys an Apartment
    Snuke's Coloring 2-1
    P1087 FBI树
    Card Game for Three
    Many Formulas
    排队
    苹果消消乐(尺取法)
    猴子选大王(约瑟夫)
    进制转化
    UIProgress控件的属性和方法
  • 原文地址:https://www.cnblogs.com/cccczh/p/5754132.html
Copyright © 2011-2022 走看看