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. 成功解决internal/modules/cjs/loader.js:596 throw err; ^ Error: Cannot find module 'express'

    ^ Error: Cannot find module 'express'根据提示我们就可以知道,没有找到express这个模块,解决办法就是:npm install express

  2. vue2 作用域插槽slot-scope详解

    插槽分为单个插槽,具名插槽,还有作用域插槽,前两种比较简单这里就不赘述了,今天的重点是讨论作用域插槽. 简单来说,前两种插槽的内容和样式皆由父组件决定,也就是说显示什么内容和怎样显示都由父组件决定: ...

  3. html计时发送验证码功能的实现

    function countdown() { var time=60; setTime=setInterval(function(){ if(time<=0){ clearInterval(se ...

  4. class类初始化之后调用赋值问题记录

    class PWSTRDELL: def __init__(self, pw_str):#该方法在类实例化时会自动调用 self.pw = pw_str self.strength_level = 0 ...

  5. PAT 1136 A Delayed Palindrome

    1136 A Delayed Palindrome (20 分)   Consider a positive integer N written in standard notation with k ...

  6. STRANS一:简单的XML转换

    心情不好,泥总把表妹微信给冰冰了,心塞... 1.简单的单层结构: <?sap.transform simple?> <tt:transform xmlns:tt="htt ...

  7. 【PAT】反转链表

    PAT 乙级 1025 给定一个常数 K 以及一个单链表 L,请编写程序将 L 中每 K 个结点反转.例如:给定 L 为 1 → 2 → 3 → 4 → 5 → 6,K 为 3,则输出应该为 3 → ...

  8. 解决Eclipse中.properties文件中文乱码问题

    在.properties文件写注释时,发现中文乱码了,由于之前在idea中有见设置.properties文件的编码类型,便找了找乱码原因 在中文操作系统中,Eclipse中的Java类型文件的编码的默 ...

  9. oracle数据库自学笔记(持续更新中……)

    以前的项目都是使用mysql数据库开发的,如今进了新的公司,开始接触到了Oracle数据库,而自己以前没有接触过,就自己挤时间来学习一下. 一.关系型数据库的概念 关系型数据理论由E.F.Codd博士 ...

  10. C#中d的??和?

    在C#中??和?分别是什么意思?   1. 可空类型修饰符(?):引用类型可以使用空引用表示一个不存在的值,而值类型通常不能表示为空.例如:string str=null; 是正确的,int i=nu ...