题目描述

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. P6091-[模板]原根

    正题 题目链接:https://www.luogu.com.cn/problem/P6091 题目大意 给出一个数\(p\),求出它的所有在\([0,p]\)的原根. 解题思路 原根的定义,\(\de ...

  2. CF618F-Double Knapsack【结论】

    正题 题目链接:https://www.luogu.com.cn/problem/CF618F 题目大意 给出大小为\(n\),值域为\([1,n]\)的两个可重集合\(A,B\) 需要你对它们各求出 ...

  3. Javascript设计模式之原型模式、发布订阅模式

    原型模式 原型模式用于在创建对象时,通过共享某个对象原型的属性和方法,从而达到提高性能.降低内存占用.代码复用的效果. 示例一 function Person(name) { this.name = ...

  4. SpringBoot整合jdbc及整合Druid数据源

    一.整合jdbc 1.创建一个springInitializr项目 勾选 web----springweb.SQL----JDBC API,MYSQL Diver 2.连接数据库 3.创建yml 4. ...

  5. Linux下Electron loadURL报错 ERR_FAILED(-2) Not allowed to load local resource

    Linux下Electron loadURL报错 ERR_FAILED(-2) Not allowed to load local resource 背景 使用electron-vue的时候,窗体创建 ...

  6. Idea进行java应用的远程调试Remote debugging

    本文可以解决如下两个问题: 1.如何处理和调试那些只发生在生产环境(或其他远程环境)而本地开发环境可能没办法重现的"问题". 2.只有一个可以部署的war/jar包,只有class ...

  7. 魔改swagger:knife4j的另外一种打开方式

    之前公司使用了swagger作为文档管理工具,原生的swagger-ui非常丑,之后就用了开源项目 萧明 / knife4j 的swagger组件进行了swagger渲染,改造之后界面漂亮多了,操作也 ...

  8. docker环境下搭建python3.6

    前言:当我们在一台电脑上搭建了python3.6的环境,下次换了个电脑或者换成linux的系统了又得重新搭建一次,设置环境变量,下载pip等操作.所以使用docker 一.安装python步骤: 1. ...

  9. 【UE4 C++】 启动 / 关闭外部exe、开启虚拟键盘

    启动/关闭外部exe 引擎自带 FPlatformProcess::CreateProc() FPlatformProcess::TerminateProc() windows api ShellEx ...

  10. Google Object detection配置与使用

    Google Object detection 前言: 本文记录了使用Google发布的Object detection(July 1st, 2019)接口,完成了对标注目标的检测.参考了很多博文,在 ...