大数加法 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]={} ...
随机推荐
- iOS 9已下的获取APP进程信息
- (NSDictionary *)getAppInfo:(NSString *)exec withBundleID:(NSString *)bundle { if ([exec isKindOfCl ...
- Shell中括号的作用
Shell中括号的作用 作者:Danbo 时间:2015-8-7 单小括号() ①.命令组.括号中的命令将会断开一个子Shell顺序执行,所以括号中的变量不能被脚本余下的部分使用.括号中多个命令之间用 ...
- Linux下Redis C++操作的封装
安装和启动Redis服务...略!很粗糙的版本,待改进... Redis Client C++示例代码...略! /** * Time: 14-3-10 * File: RedisCache.h * ...
- jquery特效(3)—轮播图①(手动点击轮播)
写了一个轮播图练练手,先写了一个手动点击轮播的轮播图,随后我会慢慢接着深入写自动轮播图和鼠标悬浮图片停止移动轮播图等,虽然今天我生日,但是代码还是得写的,不能找借口放松自己,原地踏步也算后退. 下面来 ...
- 一个selenium笔试题——去哪网首页获取符合要求的url并保存
今天在群里看到这样一个笔试题:请使用任何熟悉的面向对象编程语言,编写代码,获取http://www.qyer.com页面中,所有</a>标签"href"属性值包含英文单 ...
- 查看系统信息,区分Centos和Ubuntu
查看系统信息,区分Centos和Ubuntu # cat /etc/issue \S Kernel \r on an \m centos $ cat /etc/issue Ubuntu 16.04.4 ...
- 理解HTML解析过程
浏览器解析html的过程是:接受网络数据->将二进制码变成字符->将字符变为unicode code points.->tokenizer ->tree constructor ...
- 【转载】Android进程保活招式大全
原文地址:http://dev.qq.com/topic/57ac4a0ea374c75371c08ce8 目前市面上的应用,貌似除了微信和手Q都会比较担心被用户或者系统(厂商)杀死问题.本文对 An ...
- match_parent 、 fill_parent 、 wrap_content
1)fill_parent 设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间.这跟Windows控件的dockstyle属性大体一致. 设置一个顶部布局或 ...
- 洛谷 1082 同余方程——exgcd(水题)
题目:https://www.luogu.org/problemnew/show/P1082 大水题. #include<iostream> #include<cstdio> ...