大数加法 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]={} ...
随机推荐
- 向sd卡读写数据
/data/data 是本地存储 /storage/ 是外部存储 SD卡存储 <uses-permission android:name="android.permission.WRI ...
- POSTGRESQL主备部署模式
一.预期目的 主数据库(Primary pg ,假定主机名为A,后文不再赘述)和备用数据库(Standby pg,假定主机名为B,后文不再赘述)之间的数据能够相互备份. 主数据库发生故障时备用数据库可 ...
- wifi方式调试android程序
1. 通过wifi, 利用adb来连接手机. 在pc的cmd中输入命令: adb connect 192.168.1.100 其中adb就是手机的ip. 如果连接成功, 就可以进入android的sh ...
- this.triggerEvent()用法
在对组件进行封装时 在当前页面想要获取组件中的某一状态,需要使用到this.triggerEvent(' ',{},{}),第一个参数是自定义事件名称,这个名称是在页面调用组件时bind的名称,第二个 ...
- Java笔记(七)
File类: import java.io.File; import java.io.IOException; public class Demo{ public static void main(S ...
- kitti数据集标定文件解析
1.kitti数据采集平台 KITTI数据集的数据采集平台装配有2个灰度摄像机,2个彩色摄像机,一个Velodyne64线3D激光雷达,4个光学镜头,以及1个GPS导航系统.图示为传感器的配置平面图, ...
- ubuntu 使用命令行清空回收站
sudo rm -rf ~/.local/share/Trash/*
- UVA11624(bfs最短路)
Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the m ...
- calico在docker上的部署及验证
1. 背景 以下的部署以五台服务器环境为例: 服务器1: hostname为etcdnode1, IP为192.168.56.100 服务器2: hostname为etcdnode2, IP为192. ...
- calicoctl命令简介
背景 在calico中,有多种网络资源.以v1.6.1为例,网络资源包含:node,bgpPeer,hostEndpoint,workloadEndpoint,ipPool,policy,profil ...