当前位置:网站首页>高精度乘法
高精度乘法
2022-08-10 22:47:00 【Ding Jiaxiong】
题目
给定两个非负整数(不含前导 0) A 和 B,请你计算 A×B 的值。
输入格式
共两行,第一行包含整数 A,第二行包含整数 B。
输出格式
共一行,包含 A×B 的值。
数据范围
1≤A的长度≤100000,
0≤B≤10000
输入样例:
2
3
输出样例:
6
思路分析



题解
#include <iostream>
#include <vector>
using namespace std;
vector<int> mul(vector<int> &A, int b)
{
vector<int> C;
int t = 0;
for (int i = 0; i < A.size() || t; i ++ )
{
if (i < A.size()) t += A[i] * b;
C.push_back(t % 10);
t /= 10;
}
while (C.size() > 1 && C.back() == 0) C.pop_back();
return C;
}
int main()
{
string a;
int b;
cin >> a >> b;
vector<int> A;
for (int i = a.size() - 1; i >= 0; i -- ) A.push_back(a[i] - '0');
auto C = mul(A, b);
for (int i = C.size() - 1; i >= 0; i -- ) printf("%d", C[i]);
return 0;
}

边栏推荐
猜你喜欢

二叉树 | 层序遍历 | leecode刷题笔记

这款可视化工具神器,更直观易用!太爱了

(PC+WAP)带手机端pbootcms模板铝合金类网站

MySQL学习笔记(1)——基础操作

手机端出现Z-Fighting现象

Power system power flow calculation (Newton-Raphson method, Gauss-Seidel method, fast decoupling method) (Matlab code implementation)

MySQL performance schema性能分析实战

分享一个后台管理系统可拖拽式组件的设计思路

Glide监听Activity生命周期源码分析

DC-7靶场下载及渗透实战详细过程(DC靶场系列)
随机推荐
N1BOOK writeup
【Linux】宝塔面板设置MySQL慢查询日志,未走索引日志
OneNote 教程,如何在 OneNote 中整理笔记本?
Pytorch面试题面经
STL-stack
LeetCode Daily 2 Questions 02: Reverse the words in a string (1200 each)
How to be a Righteous Hacker?What should you study?
Mysql之部分表主从搭建及新增表
mysql中的三大日志
【640. Solving Equations】
基于交流潮流的电力系统多元件N-k故障模型研究(Matlab代码实现)【电力系统故障】
Fatal error: cstring: No such file or directory
【MySQL】mysql因为字符集导致left join出现Using join buffer (Block Nested Loop)
带你造轮子,自定义一个随意拖拽可吸边的View
基于深度学习的三维点云分割综述
Power system power flow calculation (Newton-Raphson method, Gauss-Seidel method, fast decoupling method) (Matlab code implementation)
MySQL:MySQL的集群——主从复制的原理和配置
MySQL: MySQL Cluster - Principle and Configuration of Master-Slave Replication
virtual address space
OneNote tutorial, how to organize notebooks in OneNote?