题目描述

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. python读Excel方法(xlrd)

    在我们做平常工作或自动化测试中都会遇到操作excel,Python处理exc相当顺手,如何通过python操作excel,当然python操作excel的库有很多,比如pandas,xlwt/xlrd ...

  2. 自然语言处理标注工具——Brat(安装、测试、使用)

    一.Brat标注工具安装 1.安装条件: (1)运行于Linux系统(window系统下虚拟机内linux系统安装也可以) (2)目前brat最新版本(v1.3p1)仅支持python2版本运行使用( ...

  3. Dapr + .NET Core实战(十一)单机Dapr集群负载均衡

    如何单机部署Dapr集群 第十篇讲过了K8S集群下如何使用Dapr运行程序,但是很多人一直在问如何单机下进行Dapr的负载,这节课我们来聊聊如何单机进行Dapr的负载. 首先要说的是单机下,通过 da ...

  4. python3 拼接字符串方法

    python3.x拼接字符串一般有以下几种方法: 1. 直接通过(+)操作符拼接 1 2 s = 'Hello'+' '+'World'+'!' print(s) 输出结果:Hello World! ...

  5. WEB 标准以及 W3C 的理解与认识

    01.  WEB标准 ①  web标准 简单来说可以分为结构.表现和行为. ②  结构:主要是有HTML标签组成(通俗点说,在页面body里面我们写入的标签都是为了页面的结构)   表现:即指css样 ...

  6. WPF实现Win10汉堡菜单

    WPF开发者QQ群: 340500857  | 微信群 -> 进入公众号主页 加入组织 前言 有小伙伴提出需要实现Win10汉堡菜单效果. 由于在WPF中没有现成的类似UWP的汉堡菜单,所以我们 ...

  7. python3去除行号

    问题:在复制一些代码时会同时复制每行的行号,删除比较麻烦,所以利用python3本身的代码进行一键删除. # 导入re 模块来使用正则表达式 import re """去 ...

  8. 极简实用的Asp.NetCore框架再新增商城模块

    概述 关于这个框架的背景,在前面我已经交代过了.不清楚的可以查看这个链接 1.极简实用的Asp.NetCore模块化框架决定免费开源了 2.极简实用的Asp.NetCore模块化框架新增CMS模块 算 ...

  9. stm32中的串口通信你了解多少

    在基础实验成功的基础上,对串口的调试方法进行实践.硬件代码顺利完成之后,对日后调试需要用到的printf重定义进行调试,固定在自己的库函数中. b) 初始化函数定义: void USART_Confi ...

  10. Python3 TypeError: initial_value must be str or None, not bytes

    response.read() returns an instance of bytes while StringIO is an in-memory stream for text only. Us ...