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>
#include <math.h>
#define N 1010
int t;
char str1[N], str2[N];
int sum1[N], sum2[N];
int main()
{
int len1, len2, num;
scanf("%d", &t);
//getchar();
num = ;
while(t--)
{
memset(sum1, , sizeof(sum1));
memset(sum2, , sizeof(sum2));
scanf("%s", str1);
scanf("%s", str2);
len1 = strlen(str1);
len2 = strlen(str2);
int i, j;
for(i = len1-, j = ; i >= ; i--)
sum1[j++] = sum1[j] + str1[i] - '';
for(i = len2-, j = ; i >= ; i--)
sum2[j++] = sum2[j] + str2[i] - '';
for(i = ; i < N; i++) {
sum2[i] += sum1[i];
if(sum2[i] >= )
{
sum2[i] -= ;
sum2[i+]++;
}
}
for(i = N-; i>= && sum2[i]==; i--)
;
printf("Case %d:\n", num++);
printf("%s + %s = ", str1, str2);
if(i>=)
{
for(; i >= ; i--)
printf("%d", sum2[i]);
}
else
printf("");
if(t)//注意格式
printf("\n\n");
else
printf("\n");
}
return ;
}

hdoj 1002 A+B(2)的更多相关文章

  1. hdoj 1002 A + B Problem II

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

  2. hdoj 1002 A + B Problem II【大数加法】

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

  3. hdoj 1002 A + B Problem II 高精度 java

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

  4. ACM中Java的应用

    先说一下Java对于ACM的一些优点吧: (1) 对于熟悉C/C++的程序员来说Java 并不难学,两周时间基本可以搞定一般的编程,再用些时间了解一下Java库就行了.Java的语法和C++非常类似, ...

  5. DFS ZOJ 1002/HDOJ 1045 Fire Net

    题目传送门 /* 题意:在一个矩阵里放炮台,满足行列最多只有一个炮台,除非有墙(X)相隔,问最多能放多少个炮台 搜索(DFS):数据小,4 * 4可以用DFS,从(0,0)开始出发,往(n-1,n-1 ...

  6. 【2017多校训练08 1002】【HDOJ 6134】Battlestation Operational

    典型的数列反演题. 运用莫比乌斯反演的一个结论 $[n = 1] = \sum_{d | n} \mu(d)$,将表达式做如下转化: $$ ans = \sum_{i=1}^n \sum_{j=1}^ ...

  7. HDOJ 4884 & BestCoder#2 1002

    TIANKENG’s rice shop Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  8. 杭电hdoj题目分类

    HDOJ 题目分类 //分类不是绝对的 //"*" 表示好题,需要多次回味 //"?"表示结论是正确的,但还停留在模块阶 段,需要理解,证明. //简单题看到就 ...

  9. HDOJ 题目分类

    HDOJ 题目分类 /* * 一:简单题 */ 1000:    入门用:1001:    用高斯求和公式要防溢出1004:1012:1013:    对9取余好了1017:1021:1027:   ...

随机推荐

  1. 监控平台项目之CSS总结——基于angularjs、bootstrap、jquery等框架

    1.新加一个类名,实现切换页面主题 在需要变色的标签处,添加该类名,即可实现最简化切换页面主题. HTML: <section ui-view=""> </sec ...

  2. Delphi 完整的Bug决议工具EurekaLog的使用

     http://blog.csdn.net/akof1314/article/details/6968587 Delphi 完整的Bug决议工具EurekaLog的使用 标签: delphi工具ftp ...

  3. WPF自适应窗体实现小结

    WPF自适应窗体实现小结 这几天,因工作需要,要对一个小软件进行UI调整.主要内容就是让其能够实现自适应窗体(包括文字和图标),做成像WIN7下的Media Center一样的UI.自适应窗体,顾名思 ...

  4. StaticPagedList

    估计是因为水平原因,之前看别人写的用pagedList分页,老是云里雾里的.下面把自己写的整理一下放在上面.这里的List为对应页面展示的内容.不用查询所有. Action: public Actio ...

  5. NLua - 基于Lua的C#脚本引擎

    Nlua NLua is the bind between Lua world and the .NET world. NLua is a fork of project LuaInterface ( ...

  6. LDAP与migrationtools 导入系统账号

    1:安装migrationtools yum -y install migrationtools 2:修改配置文件 cd     /usr/share/migrationtools 可以看到很多的文件 ...

  7. Android根据文件路径加载指定文件

    Android根据指定的文件路径加载指定文件格式(图片格式 png, gif,jpg jpeg)的文件相关信息的列表. 如图: 代码: public class Util { /**** * 计算文件 ...

  8. Expected one result (or null) to be returned by selectOne(), but found 2

    这个问题在于你查询sql返回结果是多个值.一个集合,但是你在service的实现层的dao都调用了.get方法.而是应该使用.getlist方法等.

  9. 解决跑twoBitToFa时出现“/admin/exe/linux.x86_64/twoBitToFa: Permission denied”的问题

    出现这种问题时,一般要加上以下命令: chmod ugo+x ./admin/exe/linux.x86_64/twoBitToFa 运行成功后,再将twobit格式转化为fa格式 ./admin/e ...

  10. 【译】RabbitMQ:路由(Routing)

    在前一篇中,我们构建了一个简单的日志系统,我们已经能够广播消息到许多的接收者.在这一篇中,我们希望增加一个特性,让订阅消息的子集成为可能.例如,我们可以将重要的错误日志存放到日志文件(即,磁盘上面), ...