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

 
Author
Ignatius.L

这是一道简单的加法题,但是数字特别大,就连long long都装不下那种~
需要用字符串来装输入数据
再按照类似小学列竖式的方法来计算……
因为竖式是从右往左,所以先把a,b字符串反转,计算完以后再反转回去~

#include<iostream>
#include<cstring> using namespace std; char a[],b[],res[];
char cha(char a); void add(); int main()
{
int t;
cin>>t;
for(int i=;i<=t;i++)
{
cin>>a>>b;
cout<<"Case "<<i<<":"<<endl<<a<<" + "<<b<<" = ";
add();
cout<<res<<endl;
if(i==t) break;
cout<<endl;
memset(res,,sizeof(res));
memset(a,,sizeof(a));
memset(b,,sizeof(b));
}
return ;
} void add()
{
int len1,len2,len,i,j;
len1=strlen(a);
len2=strlen(b);
len=max(len1,len2);
strrev(a);
strrev(b);
for(i=;i<len;i++)
{
char t=cha(res[i]);
res[i]=(char)((t+(cha(a[i])+cha(b[i]))%)%+'');
res[i+]=(t+cha(a[i])+cha(b[i]))/+'';
}
if(res[len]=='') res[len]='\0';
strrev(res);
if(res[]=='')
{
for(i=;res[]=='';i++)
{
for(j=;j<len;j++)
{
res[j]=res[j+];
}
}
}
} char cha(char a)
{
if(a!='\0') return a-'';
else return '\0';
}

大数字加法(hduoj)的更多相关文章

  1. Java BigDecimal大数字操作

    在java中提供了大数字的操作类,即java.math.BinInteger类和java.math.BigDecimal类.这两个类用于高精度计算,其中BigInteger类是针对大整数的处理类,而B ...

  2. 初识Java(Java数字处理类-大数字运算)

    一.大数字运算 在 Java 中提供了大数字的操作类,即 java.math.BigInteger 类与  java.math.BigDecimal 类.这两个类用于高精度计算,体重 BigInteg ...

  3. 剑指offer第12题打印从1到n位数以及大整数加法乘法

       字符和数字加减就是字符的ASCII码和数字直接加减. 方法一: 1)在字符串操作中给一个整形数字加(字符0)就是把它转化为字符,当然给一个字符减去(字符0)就可以把它转化为数字了:如果确实是最后 ...

  4. 学习Java的第十七天——大数字运算

    学习内容:大数字运算 代码实现: package 数字处理类; import java.math.BigInteger; public class BigIntegerDemo { public st ...

  5. AC日记——大整数加法 openjudge 1.6 10

    10:大整数加法 总时间限制:  1000ms 内存限制:  65536kB 描述 求两个不超过200位的非负整数的和. 输入 有两行,每行是一个不超过200位的非负整数,可能有多余的前导0. 输出 ...

  6. C#实现大数字的运算

    1.添加引用:System.Numerics.dll 2.添加命名空间:using System.Numerics; 3.实例: 3.1判断一个数字是不是质数 static void Main(str ...

  7. POJ2389: 大数字乘法算法

    2014-12-26 大数字乘法算法一般是采用模拟"小学生乘法演算过程”方法. 主要算法思想: 1. 乘数a第i)位与乘数b第j)位数字相乘,并将该乘积结果放到乘积结果数组product的第 ...

  8. [SOJ]寻找第k大数字(numberk)

    Description 经过长时间的筹备工作,在Jourk,Ronny,Plipala,阿长,阿沈等人的努力下,DM实验室建立起自己的系列网站,其中包括三个大板块:DMOJ首页.DMOJ论坛.DMOJ ...

  9. HDU1002——大整数加法

    题目: I have a very simple problem for you. Given two integers A and B, your job is to calculate the S ...

随机推荐

  1. 上海高校程序设计联赛 D-CSL的字符串 栈模拟

    题目链接:https://ac.nowcoder.com/acm/contest/551/D ASCII码表示的字符转换成整数实测不超过200(具体多少懒得查了) 分析:要求总的字典序最小,那就让最小 ...

  2. Debian Nginx 下载 .apk 文件时候报 403 错误 [1]

    一.版本介绍 Degian : 8 jessie Nginx  : 1.6.2 发生时间 : 2018-12-15 二.问题说明 客户浏览器访问Nginx的公开目录中放入了一个.apk文件,公开目录可 ...

  3. linux所有命令不能用显示-bash: ls: command not found

    所有的命令都显示找不到了,原因是修改了/etc/profile造成的 解决方法 1.修正属性文件中的错误 /usr/bin/vi /etc/profile 2.生效属性文件 source /etc/p ...

  4. php上传文件,接口是java,go。

    $uri = ‘https://www.xxx.com/api/xxxxx’; $ch = curl_init(); //加@符号curl就会把它当成是文件上传处理 $tmpName = $_FILE ...

  5. 学号 20175212 《Java程序设计》第4周学习总结

    学号 20175212 <Java程序设计>第4周学习总结 教材学习内容总结 一. 子类与父类 父类中的private和友好访问权限的成员变量不会被子类继承.子类只继承父类中的protec ...

  6. Win10系列:C#应用控件进阶8

    LineGeometry LineGeometry控件通过指定直线的起点和终点来定义线.LineGeometry对象无法进行自我绘制,因此同样需要使用 Path元素来辅助呈现.LineGeometry ...

  7. SQL Join 与 In的效率

    今天在优化朋友的一个系统, 主要他们前期是叫人外包写的, 越来越慢, 导出订单明细时, 基本都是TimeOut, 我查看到这里面是这样写: select * from Orders where ID ...

  8. 阿里云Oss对象存储

    将文件保存到阿里云上. 1.添加对象存储OSS空间 (新建Bucket) 可以在阿里云后台对象存储里面添加,也可以通过api添加.添加之后设置权限. skd使用. 1安装 Aliyun.OSS.SDK ...

  9. Linux c 获取cpu使用率(2)

    上一篇博文当中,我们谈论了在Linux中如何获取执行命令行的结果,最终得到cpu的 使用率,但是十分不幸的事情是: 1)通过top -n 1 | grep Cpu获取的cpu使用率不会刷新,每次读取结 ...

  10. OpenCV(一):集成

    开这个系列文章,记录自己在项目中使用OpenCV所走的步骤流程,方便以后再次使用.如果有不正确的地方,欢迎指正. OpenCV在其官网上,已经发布有iOS版的库,但是只有核心模块的功能,扩展模块(比如 ...