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

边栏推荐
- DC-7靶场下载及渗透实战详细过程(DC靶场系列)
- Power system power flow calculation (Newton-Raphson method, Gauss-Seidel method, fast decoupling method) (Matlab code implementation)
- STL-deque
- 虚拟地址空间
- 常见的加密方式有哪几种,各有哪些优缺点
- CFdiv2-Beautiful Mirrors-(期望)
- Introduction to the use of counter instructions in Rockwell AB PLC RSLogix5000
- 诺诚健华通过注册:施一公家族身价15亿 高瓴浮亏5亿港元
- BM13 determines whether a linked list is a palindrome
- MySQL:MySQL的集群——主从复制的原理和配置
猜你喜欢
随机推荐
DC-9靶场下载及渗透实战详细过程(DC靶场系列)
STL-stack
确诊了!是Druid1.1.20的锅,查询无法映射LocalDateTime类型(带源码解析及解决方案)
二叉树 | 递归遍历 | leecode刷题笔记
怎么关闭电脑广告
《DevOps围炉夜话》- Pilot - CNCF开源DevOps项目DevStream简介 - feat. PMC成员胡涛
LeetCode Daily 2 Questions 02: Reverse the words in a string (1200 each)
一、ICESat-2数据查询,下载,与处理
面试官: AMS在Android起到什么作用,简单的分析下Android的源码
带你造轮子,自定义一个随意拖拽可吸边的View
Research on multi-element N-k fault model of power system based on AC power flow (implemented by Matlab code) [Power System Fault]
实例054:位取反、位移动
电力系统潮流计算(牛顿-拉夫逊法、高斯-赛德尔法、快速解耦法)(Matlab代码实现)
koa框架(一)
VulnHub之DC靶场下载与DC靶场全系列渗透实战详细过程
68: Chapter 6: Develop article services: 1: Content sorting; article table introduction; creating [article] article services;
Mysql之部分表主从搭建及新增表
KRONES克朗斯电源维修0-901-17-350-8技术概论
gcc492 compile `.rodata‘ can not be used when making a PIE object; recompile with -fPIE
如何反弹shell









