当前位置: 首页 > news >正文

大数相乘,大数相加

大数相乘: 

#include <iostream>
#include <vector>
#include <string>std::vector<int> multiply(const std::vector<int>& num1, const std::vector<int>& num2) {int n1 = num1.size();int n2 = num2.size();std::vector<int> result(n1 + n2, 0);for (int i = n1 - 1; i >= 0; --i) {int carry = 0;for (int j = n2 - 1; j >= 0; --j) {int sum = num1[i] * num2[j] + result[i + j + 1] + carry;result[i + j + 1] = sum % 10;carry = sum / 10;}result[i] += carry;}// 去除前导零int i = 0;while (i < result.size() && result[i] == 0)++i;if (i == result.size())return {0};return std::vector<int>(result.begin() + i, result.end());
}int main() {std::vector<int> num1 = {1, 2, 3};std::vector<int> num2 = {4, 5, 6};std::vector<int> product = multiply(num1, num2);for (int digit : product) {std::cout << digit;}std::cout << std::endl;return 0;
}

http://www.lryc.cn/news/440881.html

相关文章:

  • Spring Boot配置文件敏感信息加密
  • Java操作数栈分析
  • C#|.net core 基础 - 值传递 vs 引用传递
  • axure的下载,激活,汉化全过程,多图
  • LCR 026
  • 万能小程序运营管理系统 _requestPost 任意文件读取漏洞复现
  • libyuv之linux编译
  • vue3路由基本使用
  • 哪些人适合学习人工智能?
  • 计算机的错误计算(九十七)
  • Flask-Migrate的使用
  • python怎么输入整数
  • 代码随想录打卡Day36
  • 速盾:凡科建站开cdn了吗?
  • python贪吃蛇游戏项目源码【免费】
  • Mycat搭建分库分表
  • Python中的数据结构
  • mysql笔记8(多表查询)
  • typescript-tsconfig文件解释
  • 所有用贪心的算法和所有用动态规划(dp)的算法合集
  • 论文阅读 | 基于流模型和可逆噪声层的鲁棒水印框架(AAAI 2023)
  • 上线跨境电商商城的步骤
  • Python基础(七)——PyEcharts数据分析(面向对象版)
  • 滚雪球学SpringCloud[5.1讲]: Spring Cloud Config详解
  • Unity常用随机数算法
  • dial unix /var/run/docker.sock: connect: permission denied
  • Prompt提示词技巧
  • 滑动窗口(6)_找到字符串中所有字母异位词
  • 【无标题】rocket
  • Maven国内镜像(四种)