当前位置:网站首页>高精度加法
高精度加法
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;
}

边栏推荐
- Example 045: Summation
- 【图像分类】2022-ResMLP
- 【二叉树-中等】687. 最长同值路径
- 实例047:函数交换变量
- 自动化测试中,测试数据与脚本分离以及参数化方法
- 【8.8】代码源 - 【不降子数组游戏】【最长上升子序列计数(Bonus)】【子串(数据加强版)】
- storage of data in memory
- 2022.8.8 Exam questions for photographer Lao Ma (photographer)
- 2022.8.9 Exam arrangement and transformation--1200 questions solution
- [Red Team] ATT&CK - Self-starting - Self-starting mechanism using LSA authentication package
猜你喜欢

数据治理(五):元数据管理

【Image Classification】2022-ResMLP

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

【二叉树-中等】2265. 统计值等于子树平均值的节点数

idea 删除文件空行

【二叉树-中等】1261. 在受污染的二叉树中查找元素

Anchor_generators.py analysis of MMDetection framework

【二叉树-简单】112. 路径总和

深度学习(五) CNN卷积神经网络

2022 Top Net Cup Quals Reverse Partial writeup
随机推荐
QT模态对话框及非模态对话框学习
HRnet
跨站请求伪造(CSRF)攻击是什么?如何防御?
The flask to add and delete
小菜鸟河北联通上岗培训随笔
2022年立下的flag完成情况
2022.8.8考试区域链接(district)题解
“双枪”木马病毒的进化史
2022.8.9考试排列变换--1200题解
liunx PS1 settings
QT modal dialog and non-modal dialog learning
【Kali安全渗透测试实践教程】第6章 密码攻击
storage of data in memory
数据库治理利器:动态读写分离
idea 删除文件空行
IDEA自动生成serialVersionUID
实例048:数字比大小
mysql -sql编程
【图像分类】2022-ConvMixer ICLR
Open3D 中点细分(网格细分)