当前位置:网站首页>acwing 高精度乘法
acwing 高精度乘法
2022-06-12 16:08:00 【_刘小雨】
给定两个非负整数(不含前导 0) A 和 b,请你计算 A×b 的值。
输入格式
共两行,第一行包含整数 A,第二行包含整数 b。
输出格式
共一行,包含 A×b 的值。
数据范围
1≤A的长度≤100000,
0≤b≤10000
输入样例:
2
3
输出样例:
6
记忆: 'a' = 97 , 'A' = 65, '0' = 48 常见的ASCII码
思路: 不管乘以几位数,都当作乘以1位数的思路区交给计算机算
#include <iostream>
#include <vector>
using namespace std;
const int N = 100010;
vector<int> multi(vector<int>& A, int b)
{
vector<int> re;
int t = 0; // 表示进位
for(int i=0; i<A.size() || t; i++)
{
// A没有遍历完
if(i < A.size()) t += A[i] * b;
re.push_back(t % 10);
t /= 10;
}
// 去掉前导0, 例如 000009
while(re.size()> 1 && re.back() == 0) re.pop_back();
return re;
}
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 = multi(A, b);
for(int i=C.size() - 1; i>=0 ;i--) cout<< C[i];
return 0;
}
边栏推荐
- nohup 命令使用
- < 山东大学软件学院项目实训 > 渲染引擎系统——点云处理(十)
- 面试:了解装箱和拆箱操作吗?
- Great God cracked the AMD k6-2+ processor 22 years ago and opened the hidden 128KB L2 cache
- Keep an IT training diary 067- good people are grateful, bad people are right
- Step by step steps to create an ABAP program with a custom screen
- In 2020, the demand for strain sensors in China will reach 9.006 million, and the market scale will reach 2.292 billion yuan [figure]
- 5g new scheme! Upgrade the existing base station and UE simulator to 5g millimeter wave band
- Match single character
- Data analysis | kmeans data analysis
猜你喜欢

FPGA (III) trigger and latch

5g new scheme! Upgrade the existing base station and UE simulator to 5g millimeter wave band

C packing and unpacking

Servlet knowledge explanation (2)

Project training of Software College of Shandong University rendering engine system basic renderer (IV)

Unicom Network Management Protocol block diagram

C language partition bin file program

借助SpotBugs将程序错误扼杀在摇篮中

超详细干货!Docker+PXC+Haproxy搭建高可用强一致性的MySQL集群

Applet: how to get the user's mobile number in the plug-in
随机推荐
Escape analysis of golang compiler
Dongmingzhu talks about batteries: the most essential thing is safety
FPGA (III) trigger and latch
Learning record [email protected] understand canvas
借助SpotBugs将程序错误扼杀在摇篮中
Multimix:从医学图像中进行的少量监督,可解释的多任务学习
< 山东大学软件学院项目实训 > 渲染引擎系统——基础渲染器(七)
[practical case of light source] UV-LED curing innovation makes the production line more smooth
TS 22.011
Global and Chinese markets of automatic glue applicators 2022-2028: Research Report on technology, participants, trends, market size and share
记一篇IT培训日记067-好人感恩,坏人无错
Keep an IT training diary 067- good people are grateful, bad people are right
[automation] kolla Based Automated Deployment CEPH cluster
[browser principle] variable promotion
2022.02.28 - SX11-05. The largest rectangle in the histogram
Using the CSDN markdown editor
TS 22.011
Saga体系结构模式:微服务架构下跨服务事务的实现
超详细干货!Docker+PXC+Haproxy搭建高可用强一致性的MySQL集群
Scanpy (VI) analysis and visualization of spatial transcriptome data