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. java.lang.ClassNotFoundException: org.apache.log4j.Logger 异常

    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'd ...

  2. selenium自动化定位方式

    自动化定位方式 1.String Xpath = String.format("//*[@id=\"saveFileKeyWordsBtnHand\"]/../../.. ...

  3. CentOS 7 + MySql 中文乱码解决方案

    原文:https://blog.csdn.net/qq_32953079/article/details/54629245,亲测有效,故记录之. 一.登录MySQL查看用SHOW VARIABLES ...

  4. URL组成部分详解

    URL组成部分详解 URL是Uniform Resource Locator的简写,统一资源定位符. 一个URL是由以下几部分组成的: scheme://host:port/path/?query-s ...

  5. 在idea中使用plantUML画类图

    1.下载插件,搜uml找找就有了,安装重启idea. 2.会提示你找不到graphviz,下载msi安装. 3.提示not executable,需要配置环境变量,不是配置path,配置GRAPHVI ...

  6. 免费赠送原创的opengl电子书教程和案例源码

    免费赠送原创的opengl电子书和案例源码,有兴趣qq群 52391108 下面是一部分教程截图

  7. 有价值的IPFS博客

    前一阵子研究IPFS,回头找资料有些找不到,再次汇总一下有价值的IPFS资料   戴嘉乐-IPFS的本质架构及应用:https://blog.csdn.net/u012357002/article/d ...

  8. 室内Vary 渲染部分作品

    室内Vary 渲染倍分作品

  9. SQL Server数据库开发的二十一条军规

    如果你正在负责一个基于SQL Server的项目,或者你刚刚接触SQL Server,你都有可能要面临一些数据库性能的问题,这篇文章会为你提供一些有用的指导(其中大多数也可以用于其它的DBMS).在这 ...

  10. winfrom程序Datagridview列名问题

    之前在做程序的时候,有遇到过这个问题: 无法将类型“string”隐式转换为“System.Windows.Forms.DataGridViewTextBoxColume"解决方法 解决办法 ...