【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
【AC代码】
 #include<stdio.h>
#include<string.h>
#define max(a, b) a > b ? a:b char a[];
char b[];
char c[];
int i; void reverse(char *a)
{
int aa = strlen(a);
char t;
for(i=; i<aa/; i++)
{
t = a[i];
a[i] = a[aa--i];
a[aa--i] = t;
}
}
void add(char *a, char *b, char *c)
{
int cc = , aa = strlen(a), bb = strlen(b);
int len = max(aa, bb);
for(i=; i<aa; i++)
{
a[i] = a[i]-'';
}
for(i=; i<bb; i++)
{
b[i] = b[i]-'';
}
for(i=; i<len; i++)
{
c[i] = (a[i]+b[i]+cc) % + '';
cc = (a[i]+b[i]+cc) / ;
}
if(cc) c[i++] = cc + '';
c[i] = '\0';
}
void print(char *c)
{
for(i = strlen(c)-; i>=; i--)
printf("%c", c[i]);
printf("\n");
}
main()
{
int n, j;
scanf("%d", &n);
for(j=; j<=n; j++)
{
memset(a, , sizeof(a));
memset(b, , sizeof(b));
memset(c, , sizeof(c));
scanf("%s %s", a, b);
printf("Case %d:\n", j);
printf("%s + %s = ", a, b);
reverse(a), reverse(b);
add(a, b, c);
print(c);
if(j != n) printf("\n");
}
}

大数的加法运算,杭电oj-1002的更多相关文章

  1. 杭电oj 1002

    #include <iostream> #include <algorithm> using namespace std; int nCases; ], n[]; ], b[] ...

  2. 杭电oj 2095 & 异或^符号在C/C++中的使用

    异或^符号,在平时的学习时可能遇到的不多,不过有时使用得当可以发挥意想不到的结果. 值得注意的是,异或运算是建立在二进制基础上的,所有运算过程都是按位异或(即相同为0,不同为1,也称模二加),得到最终 ...

  3. 『ACM C++』HDU杭电OJ | 1415 - Jugs (灌水定理引申)

    今天总算开学了,当了班长就是麻烦,明明自己没买书却要带着一波人去领书,那能怎么办呢,只能说我善人心肠哈哈哈,不过我脑子里突然浮起一个念头,大二还要不要继续当这个班委呢,既然已经体验过就可以适当放下了吧 ...

  4. C#利用POST实现杭电oj的AC自动机器人,AC率高达50%~~

    暑假集训虽然很快乐,偶尔也会比较枯燥,,这个时候就需要自娱自乐... 然后看hdu的排行榜发现,除了一些是虚拟测评机的账号以外,有几个都是AC自动机器人 然后发现有一位作者是用网页填表然后按钮模拟,, ...

  5. 用python爬取杭电oj的数据

    暑假集训主要是在杭电oj上面刷题,白天与算法作斗争,晚上望干点自己喜欢的事情! 首先,确定要爬取哪些数据: 如上图所示,题目ID,名称,accepted,submissions,都很有用. 查看源代码 ...

  6. 杭电oj 4004---The Frog Games java解法

    import java.util.Arrays; import java.util.Scanner; //杭电oj 4004 //解题思路:利用二分法查找,即先选取跳跃距离的区间,从最大到最小, // ...

  7. 杭电oj————2057(java)

    question:A+ B again 思路:额,没啥思路/捂脸,用java的long包里的方法,很简单,只是有几次WA,有几点要注意一下 注意:如果数字有加号要删除掉,这里用到了正则表达式“\\+” ...

  8. 爬取杭电oj所有题目

    杭电oj并没有反爬 所以直接爬就好了 直接贴源码(参数可改,循环次数可改,存储路径可改) import requests from bs4 import BeautifulSoup import ti ...

  9. 杭电acm 1002 大数模板(一)

    从杭电第一题开始A,发现做到1002就不会了,经过几天时间终于A出来了,顺便整理了一下关于大数的东西 其实这是刘汝佳老师在<算法竞赛 经典入门 第二版> 中所讲的模板,代码原封不动写上的, ...

  10. 杭电OJ 输入输出练习汇总

    主题 Calculate a + b 杭电OJ-1000 Input Each line will contain two integers A and B. Process to end of fi ...

随机推荐

  1. 【Java基础 】Java7 NIO Files,Path 操作文件

    从Java1.0到1.3,我们在开发需要I/O支持的应用时,要面临以下问题: 没有数据缓冲区或通道的概念,开发人员要编程处理很多底层细节 I/O操作会被阻塞,扩展能力有限 所支持的字符集编码有限,需要 ...

  2. vuejs单一事件管理组件间的通信

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. vertical-align用法

    父元素下面有两个子元素,第一个子元素设置display:inline-block,第二个子元素设置display:inline-block, vertical-align:top这样两个元素就能顶部对 ...

  4. css3圆环闪烁动画

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 初窥DB2之insert语句

    第一种写法 INSERT INTO PERSVALUES (12, 'Harris', 20, 'Sales', 5, 18000, 1000, '1950-1-1') 第二种写法 INSERT IN ...

  6. linux系统使用python监测网络接口获取网络的输入输出

    #!/usr/bin/env Pythonimport timeimport sys if len(sys.argv) > 1: INTERFACE = sys.argv[1]else: INT ...

  7. 老李分享:Web Services 特性 1

    老李分享:Web Services 特性   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨询qq:9 ...

  8. (转)Java并发编程:并发容器之ConcurrentHashMap

    下面这部分内容转载自: http://www.haogongju.net/art/2350374 JDK5中添加了新的concurrent包,相对同步容器而言,并发容器通过一些机制改进了并发性能.因为 ...

  9. (iOS)谈谈关于使用category的静态库(原创)

    最近在一个项目中使用了一个包含catecategory 的静态库,但是此项目在运行过程中,该静态库调用 category 增加的方法处,却报 selector not recognized 异常,会直 ...

  10. Spring Dubbo 开发笔记

    第一节:概述 Spring-Dubbo 是我自己写的一个基于spring-boot和dubbo,目的是使用Spring boot的风格来使用dubbo.(即可以了解Spring boot的启动过程又可 ...