大数加法 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]={} ...
随机推荐
- 7-10 社交网络图中结点的“重要性”计算(30 point(s)) 【并查集+BFS】
7-10 社交网络图中结点的"重要性"计算(30 point(s)) 在社交网络中,个人或单位(结点)之间通过某些关系(边)联系起来.他们受到这些关系的影响,这种影响可以理解为网络 ...
- 将前端文件和Go程序打包
我今天项目上碰见个需求,前端小哥给我写了个页面,要搭配我的Go程序一起使用,突然想到Go可以打包静态页面,而且调用也很方便,所以操作了一下,成功,我把它记录下来,作为以后的回顾和复习. 首先,我们需要 ...
- 原来 Set 集合也可以排序
Java 集合类主要由两个接口派生而出: Collection 和 Map.在 Collection 集合中,我们经常用到的是 List 集合和 Map 集合,而 Set 集合出场的机会就相对比较的少 ...
- git命令行删除远程分支
先查看远程分支 git branch -r 使用下面两条命令来删除远程分支 git branch -r -d origin/branch-name git push origin :branch-na ...
- poj 1743 Musical Theme【后缀自动机】
不是很神的一道题,一般. 先差分,最后答案需要+1. 一个right集的len即为该right集的最长相同后缀,考虑到不能重复,所以处理一下该right集的最大与最小的ri,最后答案ans=max(a ...
- vue的缓存机制
缓存,不管是PC 端还是移动端,不可避免的问题.vue中有一个keepAlive,这个api 基本 能实现我们开发的一些需要. 一.简单介绍下keep-alive: 1.把切换出去的组件保留在内存中, ...
- 「USACO16OPEN」「LuoguP3146」248(区间dp
题目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small to ...
- NMS 原理 了解
NMS 原理:对于Bounding Box的列表B及其对应的置信度S,采用下面的计算方式.选择具有最大score的检测框M,将其从B集合中移除并加入到最终的检测结果D中.通常将B中剩余检测框中与M的I ...
- bzoj 1096 仓库建设 —— 斜率优化DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1096 设 f[i] 为 i 作为最后一个仓库时前 i 个工厂的答案,最后的答案当然是 f[n ...
- selenium_page_object
最简单的pageobject github地址:https://github.com/defnngj/selenium_page_objects