大数加法 HDU 1002
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm> using namespace std; string bigmun(string a,string b){
string c;
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
char ans[2000];
int l=0,plus=0,i;
char x[2000];
for(i=0;i<max(a.size(),b.size())-min(a.size(),b.size());i++){
x[i]='0';
}
x[i]='\0';
string xx=x;
if(a.size()<b.size()){
a=a+xx;
}
else{
b=b+xx;
}
for(i=0;i<min(a.size(),b.size());i++){
int x=a[i]-'0';
int y=b[i]-'0';
int z=x+y;
z+=plus;
plus=0;
ans[l++]=z%10+'0';
plus+=z/10;
}
if(plus!=0){
ans[l++]=plus+'0';
}
ans[l]='\0';
c=ans;
reverse(c.begin(), c.end());
return c;
} int main(){
int n;
scanf("%d",&n);
int Case;
Case=1;
while (n--) {
string a,b,c;
cin>>a>>b;
c=bigmun(a,b);
printf("Case %d:\n",Case++);
if(n!=0){
cout<<a<<" "<<"+"<<" "<<b<<" "<<"="<<" "<<c<<endl;
cout<<endl;
}
else{
cout<<a<<" "<<"+"<<" "<<b<<" "<<"="<<" "<<c<<endl;
}
}
return 0;
}
大数加法 HDU 1002的更多相关文章
- 大数加法~HDU 1002 A + B Problem II
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1002 题意: 数学题,A+B; 思路,这个数非常大,普通加法一定会超时,所以用大数加法.大数加法的基 ...
- 抓起根本(二)(hdu 4554 叛逆的小明 hdu 1002 A + B Problem II,数字的转化(反转),大数的加法......)
数字的反转: 就是将数字倒着存下来而已.(*^__^*) 嘻嘻…… 大致思路:将数字一位一位取出来,存在一个数组里面,然后再将其变成数字,输出. 详见代码. while (a) //将每位数字取出来, ...
- hdu 1002 A + B Problem II【大数加法】
题目链接>>>>>> 题目大意:手动模拟大数加法,从而进行两个大数的加法运算 #include <stdio.h> #include <strin ...
- HDU 1002 A - A + B Problem II (大数问题)
原题代号:HDU 1002 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 原题描述: Problem Description I have a ...
- HDU——1715大菲波数(大数加法)
大菲波数 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- A + B Problem II(大数加法)
http://acm.hdu.edu.cn/showproblem.php?pid=1002 A + B Problem II Time Limit: 2000/1000 MS (Java/Other ...
- Hat's Fibonacci(大数加法+直接暴力)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1250 hdu1250: Hat's Fibonacci Time Limit: 2000/1000 M ...
- ZZNU 2125:A + B 普拉斯(傻逼题+大数加法)
2125: A + B 普拉斯 时间限制: 1 Sec 内存限制: 128 MB 提交: 94 解决: 28 [提交] [状态] [讨论版] [命题人:admin] 题目描述 "别人总说 ...
- 51nod 1005 大数加法
#include<iostream> #include<string> using namespace std; #define MAXN 10001 },b[MAXN]={} ...
随机推荐
- linux CentOS7.2配置LNMP
转自http://www.centoscn.com/CentosServer/www/2014/0904/3673.html 准备篇: CentOS 7.0系统安装配置图解教程 http://www. ...
- Tomcat之catalina.out日志分割
可参考:http://meiling.blog.51cto.com/6220221/1911769 本人尚未验证.
- linux-unzip命令【转载】
前辈 总结的很好http://www.cnblogs.com/lucyjiayou/archive/2011/12/25/2301046.html 功能说明:压缩文件. 语 法:zip [-AcdDf ...
- 数据结构之 字符串---字符串匹配(kmp算法)
串结构练习——字符串匹配 Time Limit: 1000MS Memory limit: 65536K 题目描述 给定两个字符串string1和string2,判断string2是否为strin ...
- UVA10561 Treblecross —— SG博弈
题目链接:https://vjudge.net/problem/UVA-10561 题意: 两个人玩游戏,轮流操作:每次往里面添加一个X,第一个得到XXX的获胜. 题解: 详情请看<训练指南&g ...
- 人生苦短之Python列表拷贝
列表拷贝的几种方法: 1.工厂函数 b=list(a) >>> a=[1,2,3,4] >>> b=list(a) >>> b [1, 2, ...
- hadoop内存分配方案
Configuration File Configuration Setting Value Calculation 8G VM (4G For MR) yarn-site.x ...
- SpringMVC 注释@PathVariable
@PathVariable 是用来获得请求url中的动态参数的: @ResponseBody @RequestMapping(value="/pointUpload/{userid}&quo ...
- 「NOI2015」「Codevs4621」软件包管理器(树链剖分
4621 [NOI2015]软件包管理器 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description Linux用户和OSX用户一定对 ...
- inline关键字的用法详解
1. 引入inline关键字的原因 在c/c++中,为了解决一些频繁调用的小函数大量消耗栈空间(栈内存)的问题,特别的引入了inline修饰符,表示为内联函数. 栈空间就是指放置程序的局部数据(也就是 ...