当前位置:网站首页>高精度加法
高精度加法
2022-08-10 02:16:00 【Ding Jiaxiong】
题目
给定两个正整数(不含前导 0),计算它们的和。
输入格式
共两行,每行包含一个整数。
输出格式
共一行,包含所求的和。
数据范围
1≤整数长度≤100000
输入样例:
12
23
输出样例:
35
思路分析

【模板题】
题解
#include<iostream>
#include<vector>
using namespace std;
const int N = 10e6 + 10;
// 计算 C = A + B
// 模板
vector<int> add(vector<int> &A , vector<int> &B){
vector<int> C;
int t = 0;
for(int i = 0 ; i < A.size() || i < B.size() ; i++){
if(i < A.size()){
t += A[i];
}
if(i < B.size()){
t += B[i];
}
C.push_back(t % 10);
t /= 10;
}
if(t){
C.push_back(1);
}
return C;
}
int main(){
string a , b;
vector<int> A , B ;
cin >> a >> b;
for(int i = a.size() - 1 ; i >= 0 ; i--){
A.push_back(a[i] - '0');
}
for(int i = b.size() - 1 ; i >= 0 ; i--){
B.push_back(b[i] - '0');
}
auto C = add(A , B);
for(int i = C.size() - 1 ; i >= 0 ;i --){
printf("%d",C[i]);
}
return 0;
}

边栏推荐
猜你喜欢

Database management tool: dynamic read-write separation

别再用 offset 和 limit 分页了,性能太差!

自动化测试中,测试数据与脚本分离以及参数化方法

【二叉树-困难】124. 二叉树中的最大路径和

HackTheBox——Beep

《GB39707-2020》PDF下载

【语义分割】2022-HRViT CVPR

【二叉树-中等】508. 出现次数最多的子树元素和

In automated testing, test data is separated from scripts and parameterized methods

liunx PS1 settings
随机推荐
State compression small experience
excel高级绘图技巧100讲(二十三)-Excel中实现倒计时计数
Difference Between Data Mining and Data Warehousing
【图像分类】2022-ConvMixer ICLR
On the Harvest of Travel
第二十一章 源代码文件 REST API 参考(三)
【二叉树-中等】1261. 在受污染的二叉树中查找元素
Database management tool: dynamic read-write separation
“双枪”木马病毒的进化史
Web mining traceability?Browser browsing history viewing tool Browsinghistoryview
实例042:变量作用域
官宣出自己的博客啦
2022.8.8考试清洁工老马(sweeper)题解
2022.8.8考试区域链接(district)题解
[Kali Security Penetration Testing Practice Course] Chapter 8 Web Penetration
2022.8.9考试排列变换--1200题解
Error state based Kalman filter ESKF
2022.8.8 exam sweeps the horse (sweeper) antithesis
自动化测试中,测试数据与脚本分离以及参数化方法
剑指offer专项突击版第25天