OpenJ_Bailian 2980 || POJ 2389 大整数乘法
来源:互联网 发布:人工智能主要研究方向 编辑:程序博客网 时间:2024/05/16 01:26
题目:
http://bailian.openjudge.cn/practice/2980?lang=en_US
http://poj.org/problem?id=2389
题意:
求两个不超过200位的非负整数的积。
Input
有两行,每行是一个不超过200位的非负整数,没有多余的前导0。
Output
一行,即相乘后的结果。结果里不能有多余的前导0,即如果结果是342,那么就不能输出为0342。
Sample Input
12345678900
98765432100
Sample Output
1219326311126352690000
思路:
大整数乘法裸题,留个模板
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 1010;void multiply(char *s1, char *s2, char *s3){ int len1 = strlen(s1), len2 = strlen(s2), len3 = 0; reverse(s1, s1 + len1); reverse(s2, s2 + len2); for(int i = 0; i < len1+len2; i++) s3[i] = '0'; for(int i = 0; i < len1; i++) { int t = 0; for(int j = 0; j < len2; j++) { t += (s1[i]-'0') * (s2[j]-'0'); s3[i+j] += t%10, t /= 10; if(s3[i+j] > '9') s3[i+j] -= 10, t++; len3 = max(len3, i+j); } if(t) s3[i+len2] += t, len3 = max(len3, i+len2); } s3[++len3] = '\0'; reverse(s3, s3 + len3);}int main(){ char s1[N], s2[N], s3[N]; scanf("%s%s", s1, s2); multiply(s1, s2, s3); printf("%s", s3); return 0;}
0 0
- OpenJ_Bailian 2980 || POJ 2389 大整数乘法
- POJ 百练 2980:大整数乘法
- poj 2389Bull Math(大整数乘法, 水题)
- HDU 1402 POJ 2389 BZOJ 2179 大整数乘法 FFT
- POJ 2389——Bull Math, 大整数乘法的另一种解法
- 百练2980 大整数乘法
- 百练2980 大整数乘法
- 百炼 2980 大整数乘法
- 百练 2980 大整数乘法
- 百炼2980:大整数乘法
- 百练2980:大整数乘法题解
- POJ 1001 解题报告 高精度大整数乘法模版
- 大整数乘法
- C++大整数乘法
- 大整数FFT乘法
- 大整数乘法
- 大整数乘法
- 大整数乘法
- centos 关闭防火墙及hostname设置
- base64
- 转载redis之jedis简单使用
- Go语言学习(一)下载安装Go编译器,并配置环境变量
- [LeetCode]16.threeSumClosest
- OpenJ_Bailian 2980 || POJ 2389 大整数乘法
- C++第六次上机作业
- vi显示回车换行等特殊字符
- 结构张量structure tensor
- 深入理解javascript原型和闭包(6)——继承
- Android webview Input type=file 文件上传 解决方法
- 计算机究竟还能火多久
- c语言实现删除文件的指定行(内容)
- 需不需要学点编程