当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
![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]](/img/a8/dd5f79262fe6196dd44ba416a4baac.jpg)
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]

The common hand, the original hand and the excellent hand from the sum of Fibonacci sequence

acwing 800. 数组元素的目标和

Decision tree classification and examples

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

聊聊事件监听那些事-上

leetcode-54. Spiral matrix JS

Unicom Network Management Protocol block diagram

Task output: dense snow ice city theme song 0612

借助SpotBugs将程序错误扼杀在摇篮中
随机推荐
redis String类型常见命令
Task output: dense snow ice city theme song 0612
Job submission instructions upload jobs to network disk
Daily leetcode - 3 Longest substring without duplicate characters
Reprise de Google net
Understanding of dart typedef
(四)GoogleNet复现
What is JUC in high concurrency programming
Instructions de soumission des tâches télécharger les tâches sur le disque réseau
面试:什么是浅拷贝、深拷贝?
< 山东大学软件学院项目实训 > 渲染引擎系统——基础渲染器(七)
C语言 分割bin文件程序
Use of packet capturing tool Fiddler: simulating speed limit test process in weak network environment
Multimix:从医学图像中进行的少量监督,可解释的多任务学习
[automation] kolla Based Automated Deployment CEPH cluster
面试:hashCode()和equals()
Axure RP 9 for MAC (interactive product prototyping tool) Chinese version
glibc 内存管理模型 释放 C库内存缓存
MySQL blob and text types
Escape rules and examples of go