题目描述

I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.

A,B must be positive.

输入

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.

输出

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.

样例输入

2
1 2
112233445566778899 998877665544332211

样例输出

Case 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110
 1 /*对于此题做法有两种:
2 其一,使2字符串的中的字符数字减去'0',逐个相加大于等于10的可以使本位减10,下一位自增1,后面的处理就非常简单了;
3 其二,便是读入字符串后先让各个字符减'0',一一对应存入整形数组中;之后再相加。
4 对于2种方法大致是相同的,都要从后面向前加,逢十进位,以及数组初始化均要初始为0,一边方便运算。
5 下面用法一,代码如下:*/
6 #include<stdio.h>
7 #include<string.h>
8
9 int main( ) {
10 int n, i,len1, len2, j, k, pi, t;
11 char str1[1010], str2[1010];
12 scanf("%d", &n);
13 for(i = 1; i <= n; i++) {
14 int a[1200] = {0};
15 int flag = 0;
16 scanf("%s%s", str1, str2);//以字符串形式读入
17 printf("Case %d:\n", i);
18 len1 = strlen(str1);
19 len2 = strlen(str2);
20 printf("%s + %s = ", str1, str2);
21 j = len1-1;
22 k = len2-1;
23 pi = 0;
24 while(j >= 0 && k >= 0) { //开始相加
25 if(a[pi] + (str1[j]-'0') + (str2[j]-'0') >= 10) { //相加后大于10的
26 a[pi] = a[pi] + (str1[j] -'0')+(str2[k] - '0')-10;
27 a[pi+1]++;
28 }
29 else
30 a[pi] = a[pi] + (str1[j] - '0')+(str2[k]-'0');
31 pi++; k--; j--;
32 }
33 if(j>=0) {
34 for(t = j; t >= 0; t--) {
35 a[pi] = a[pi]+(str1[t]-'0');
36 pi ++;
37 }
38 }
39 else if(k >= 0) {
40 for(t = k; t >= 0; t--) {
41 a[pi] = a[pi] + str2[t]-'0';
42 pi++;
43 }
44 }
45 else if(a[pi]!=0)//对于位数相同2个数加后最高位大于10的
46 pi++;
47 for(t = pi - 1; t >= 0; t--) {
48 if(a[t]==0&&flag==0)
49 continue;
50 else
51 {
52 flag=1;
53 printf("%d", a[t]);
54 }
55 }
56 if(i!=n)//对于2组之间加空行的情况
57 printf("\n");
58 }
59 return 0;
60 }

问题 C: A+B Problem II的更多相关文章

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

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

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

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

  3. HDU 1002 A + B Problem II

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

  4. A + B Problem II

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

  5. nyoj 103 A + B problem II

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

  6. hdu 1023 Train Problem II

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1212 Train Problem II Description As we all know the ...

  7. 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) ...

  8. 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过

    杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...

  9. hdoj 1002 A + B Problem II

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

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

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

随机推荐

  1. kettle 多表全删全插同步数据 两种方案

    背景: 接到上级指示,要从外网某库把数据全部导入到内网,数据每天更新一次即可,大约几百万条数据,两个库结构一样,mysql的,两台数据库所在服务器都是windows server的,写个java接口实 ...

  2. ls命令剖析

    目录 ls命令剖析 资料翻译 SYNOPSIS 使用方式 DESCRIPTION 说明 参数的说明 -l 参数字符的解释 文件权限的解释 FILES 文件夹 实战演练 ls 命令 ls -l 命令 l ...

  3. vj-2021.6.5-补题

    B - B 内容: One day, as Sherlock Holmes was tracking down one very important criminal, he found a wond ...

  4. Redis大集群扩容性能优化实践

    一.背景 在现网环境,一些使用Redis集群的业务随着业务量的上涨,往往需要进行节点扩容操作. 之前有了解到运维同学对一些节点数比较大的Redis集群进行扩容操作后,业务侧反映集群性能下降,具体表现在 ...

  5. windows10安装MySQL8.0.27

    1.官网下载安装包:https://dev.mysql.com/downloads/mysql/ 2.将解压文件解压到你安装的目录:D:\mysql-8.0.27-winx64 注意:不要放在有中文名 ...

  6. paramiko远程控制host执行脚本的用法

    import paramiko ssh = paramiko.SSHClient() print ssh.get_host_keys() ssh.set_missing_host_key_policy ...

  7. Sequence Model-week2编程题1-词向量的操作【余弦相似度 词类比 除偏词向量】

    1. 词向量上的操作(Operations on word vectors) 因为词嵌入的训练是非常耗资源的,所以ML从业者通常 都是 选择加载训练好 的 词嵌入(Embedding)数据集.(不用自 ...

  8. [no code][scrum meeting] Beta 11

    $( "#cnblogs_post_body" ).catalog() 例会时间:5月26日11:30,主持者:肖思炀 下次例会时间:5月27日11:30,主持者:乔玺华 一.工作 ...

  9. RogrePirates Scrum Meeting 博客汇总

    RogrePirates 博客目录 一.Scrum Meeting 1.Alpha阶段 第一次会议 第二次会议 第三次会议 第四次会议 第五次会议 第六次会议 第七次会议 第八次会议 第九次会议 第十 ...

  10. 2020BUAA软工个人项目作业

    2020BUAA软工个人项目作业 17373010 杜博玮 项目 内容 这个作业属于哪个课程 2020春季计算机学院软件工程(罗杰 任健) 这个作业的要求在哪里 个人项目作业 我在这个课程的目标是 学 ...