A + B Problem II

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

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
 
 

  1. #include<stdio.h>
  2. #include<string.h>
  3. #define as 1000
  4. int main()
  5. {
  6. int as1[as+],as2[as+],cot=,j,t;
  7. char shuru1[as+],shuru2[as+];
  8. int n,i;
  9. scanf("%d",&n);
  10. getchar();//吸收回车符
  11. t=n;
  12. while(n--)
  13. {
  14. cot++;
  15. scanf("%s",shuru1);
  16. scanf("%s",shuru2);
  17. memset(as1,,sizeof(as1));
  18. memset(as2,,sizeof(as2));
  19. for(i=,j=strlen(shuru1)-;j>=;j--,i++)
  20. {
  21. as1[i]=shuru1[j]-'';
  22.  
  23. }
  24. for(i=,j=strlen(shuru2)-;j>=;j--,i++)
  25. {
  26. as2[i]=shuru2[j]-'';
  27. }
  28. for(i=;i<as+;i++)
  29. {
  30. as1[i]+=as2[i];
  31. if(as1[i]>=)//判断是否满十进一
  32. {
  33. as1[i+]++;
  34. as1[i]-=;
  35. }
  36.  
  37. }
  38. for(i=as+;(i>=)&&(as1[i]==);i--);//去掉结果前面多余的0
  39. printf("Case %d:\n",cot);
  40. printf("%s + %s = ",shuru1,shuru2);
  41. if(i>=)
  42. {
  43. for(;i>=;i--)
  44. printf("%d",as1[i]);
  45. }
  46. else
  47. printf("");
  48. printf("\n");
  49. if(cot!=t)
  50. printf("\n");//最后不要多换行
  51. }
  52. return ;
  53. }
 
 

A + B Problem II---hdu1002的更多相关文章

  1. (string高精度)A + B Problem II hdu1002

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. HDU1002 -A + B Problem II(大数a+b)

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. hdu1002 A + B Problem II(高精度加法) 2016-05-19 12:00 106人阅读 评论(0) 收藏

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. HDU1002 A + B Problem II 大数问题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1002 A + B Problem II Time Limit: 2000/1000 MS (Java ...

  5. hdu1002 A + B Problem II(大数题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 A + B Problem II Time Limit: 2000/1000 MS (Java/ ...

  6. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  7. nyoj 623 A*B Problem II(矩阵)

    A*B Problem II 时间限制:1000 ms  |  内存限制:65535 KB 难度:1   描述 ACM的C++同学有好多作业要做,最头痛莫过于线性代数了,因为每次做到矩阵相乘的时候,大 ...

  8. HDU 1002 A + B Problem II

    A + B Problem II   Time Limit: 1000MS      Memory Limit: 65536K Total Submissions: 16104    Accepted ...

  9. A + B Problem II

    之前总是在查阅别人的文档,看着其他人的博客,自己心里总有一份冲动,想记录一下自己学习的经历.学习算法有一段时间了,于是想从算法开始自己的博客生涯O(∩_∩)O~~ 今天在网上看了一道大数相加(高精度) ...

  10. nyoj 103 A + B problem II

    点击打开链接 A+B Problem II 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 I have a very simple problem for you. G ...

随机推荐

  1. 每天一点css3聚沙成塔(一):transition

    transition 语法: transition:[ transition-property ] || [ transition-duration ] || [ transition-timing- ...

  2. mac 更改word的默认显示比例为125

    1.打开或新建一个word文档 2.按 fn + option + F11 键,会弹出一个[项目]窗口,选中Normal, 双击[模块], 修改为125 Sub AutoOpen() ActiveWi ...

  3. nginx之依据IP做限制

    环境如下: [root@localhost ~]# cat /etc/issueCentOS release 6.5 (Final)Kernel \r on an \m[root@localhost ...

  4. django第二个项目--使用模板

    第一步: 创建新项目secondproject cd /tmp/django-admin startproject secondeproject 第二步: 创建一个用于放置模板文件夹 cd /tmp/ ...

  5. 添加鼠标右键菜单项(EditPlus为例)

    下载Editplus,发现大多是绿色版,这就导致鼠标右键快捷菜单了,使用起来不方面,上网搜集了下资料,解决方法很简单: 首先进入注册表:regedit 然后如图设置新项. 其中editplus是右键菜 ...

  6. Eclipse Clojure 开发插件

    参考:http://doc.ccw-ide.org/documentation.html#install-as-plugin 安装Eclipse Clojure插件 这里安装的插件是Countercl ...

  7. UNIX网络编程---TCP客户/服务器程序示例(五)

    一.概述 客户从标准输入读入一行文本,并写给服务器 服务器从网络输入读入这行文本,并回射给客户 客户从网络输入读入这行回射文本,并显示在标准输出上 二.TCP回射服务器程序:main函数 这里给了函数 ...

  8. UESTC_邱老师选妹子 2015 UESTC Training for Dynamic Programming<Problem H>

    H - 邱老师选妹子 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  9. 关于set和map的用法

    1.set 定义:每个元素最多只出现一次,并且默认的是从小到大排序. set 遍历: 题目http://www.cnblogs.com/ZP-Better/p/4700218.html for(set ...

  10. SoftLayer®凭借Flex Images™消融物理与虚拟服务器之间的界线

    网摘文档留存,日后有用; 达拉斯--(美国商业资讯)--随着SoftLayer Flex Images的推出,物理与虚拟IT资源之间的界线正在变得模糊.Flex Images让用户能够捕捉.复制并存储 ...