10106 - Product
来源:互联网 发布:船舶设计软件有哪些 编辑:程序博客网 时间:2024/04/29 05:50
对于大整数的四则运算,需运用数组的相关处理方法来解决,因为现行一般的系统均不超过32位。
一道Uva online上的题目,几经波折,略见成效,现将代码复制如下,还望赐教。。。。。
题目出处:uva.onlinejudge.org/index.php
#
include < iostream >
#include < cstring >
#include < cmath >
using namespace std;
const int MAX = 600;
//整形数据不会超过600百位数
char BigInt1[MAX];
char BigInt2[MAX];
int mul[MAX];
//存放最后结果
int Big1[MAX];
int Big2[MAX];
int main() {
int m, n, i, len1, len2;
while
(cin.getline(BigInt1, sizeof(BigInt1)) &&
cin.getline(BigInt2, sizeof(BigInt2))) {
len1 = strlen(BigInt1);
len2 = strlen(BigInt2);
memset(Big1, 0, sizeof(Big1));
memset(Big2, 0, sizeof(Big2));
memset(mul, 0, sizeof(mul));
for
(i = 0; i < len1; i++)
Big1[i] = BigInt1[len1 - i - 1] -
'0'
;
//将大整形数据逆序存放以便进位时的操作
for
(i = 0; i < len2; i++)
Big2[i] = BigInt2[len2 - i - 1] -
'0'
;
for
(m = 0; m < len1; m++) {
int carry = 0;
//进位标志
int t = m;
for
(n = 0; n < MAX; n++) {
int multi = Big2[n] * Big1[m] + mul[t] + carry;
mul[t] = multi % 10;
carry = multi / 10;
t++;
}
}
for
(n = MAX - 1; n >= 0; n--)
if
(mul[n])
break
;
if
(n >= 0)
//计算的结果不为0时
{
for
(m = n; m >= 0; m--)
cout << mul[m];
cout << endl;
}
else
//结果为0的特殊情况需输出
cout << 0 << endl;
}
return
0;
}
- 10106 - Product
- 10106 - Product()
- 10106 - Product
- 10106 - Product
- 10106 - Product
- 10106 - Product
- 10106 - Product
- 10106 - Product
- UVa 10106 Product
- UVa OJ 10106-Product
- Uva 10106 Product
- uva 10106 Product
- UVa 10106 - Product
- uva-10106 - Product
- UVaOJ 10106 - Product
- UVA 10106 Product
- UVA 10106 - Product
- UVa 10106 - Product
- 专业生涯规划
- 程序员之路
- 考试前
- 第一篇笔记
- 初来乍到
- 10106 - Product
- C#用标记法来求素数
- 快速排序
- 【转】李开复对计算机专业学生的几点建议
- 啊 第一篇学习笔记,什么都不写,只为赚分数
- 轻舟已过万重山——计算机达人成长之路(31)
- 简单工厂模式
- 大数四则运算的实现
- 我喜欢编程