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. charles\mitmproxy\appium的安装与使用

    一.charles安装与激活1.https://www.charlesproxy.com/documentation/installation/下载dmg包安装后要将应用添加到Mac的应用目录中,一般 ...

  2. PHP异常和错误

    一.PHP的异常和错误 异常:在程序运行中不符合预期的情况及与正常流程不同的情况.一种不正常的情况,就是按照正常逻辑不该出错,但任然出错的情况,这属于逻辑和业务流程的一种中断,而不是语法错误.PHP只 ...

  3. 在idea中使用plantUML画类图

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

  4. python小游戏,石头/剪子/布

    #从控制台输入石头(1)/剪子(2)/布(3) player=int(input("玩家出拳 石头(1)/剪子(2)/布(3)")) #电脑随机出拳 computer comput ...

  5. 【nowcoder】 4th T1 动态点分治

    题目链接:https://www.nowcoder.com/acm/contest/175/A 题目名字吓死人 std: 我 太可啪了 一道简单的模拟题.虽然我把题意想错了. 按照题意模拟输出和继承. ...

  6. C#UDP广域网,局域网通信-原理分析

    一.UDP局域网通信. 这个比较简单,关于局域网中的2台或者更多的计算机之间的UDP通信,网络上一大把,直接复制粘贴就可以使用,原理也非常简单.所以,本文不做详细介绍. 二.UDP广域通信(包括路由器 ...

  7. idea新建maven工程没有artifacts

    原理,是因为没把新创建好的maven项目给设置成一个可被tomcat部署的web项目 选择个项目路径 配置artifacts,引入到tomcat就可以

  8. Oracle中查看SQL语句的索引命中情况及CPU占用

    第一种: 在PL/SQL中,在Explain plan Window中执行要优化的Sql语句.结果,如下图: Object name列中显示了命中的索引名,Cost列显示了CPU的使用率(%). 第二 ...

  9. 使用img2html把图片转为网页

    代码如下: # -*- coding: utf-8 -*- # Nola """ img2html : Convert image to HTML optional ar ...

  10. Android Studio修改apk打包生成名称

    在app的build.gradle文件的android{}括号里添加: android.applicationVariants.all { variant -> variant.outputs. ...