UVa-10106-Product
来源:互联网 发布:微商城软件下载 编辑:程序博客网 时间:2024/06/16 17:55
AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 1. Elementary Problem Solving :: Big Number
// 10106 - Product#include <iostream>#include <cstring>//#include <cstdio>#define MAXN 1000using namespace std; char A[MAXN], B[MAXN];int a[MAXN], b[MAXN], c[MAXN]; int main(void){ //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int lenA, lenB, carry, index, t, i, j, k, n; while(cin >> A >> B) { lenA = strlen(A); lenB = strlen(B); memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); memset(c, 0, sizeof(c)); for(i=lenA-1, k=0; i>=0; i--, k++) a[k] = A[i] - '0'; for(i=lenB-1, k=0; i>=0; i--, k++) b[k] = B[i] - '0'; index = 0; for(i=0; i<=lenA; i++) { carry = 0; t = index; for(j=0; j<=lenB; j++) { carry += a[i] * b[j]; c[t] += carry % 10; carry /= 10; if(c[t] > 9) // !!! { carry += c[t] / 10; c[t] %= 10; } t++; } index++; } n = MAXN-1; while(n>0 && !c[n]) // 特别注意结果为零的情况!!! n--; // 数组不能越界到-1!!! for(i=n; i>=0; i--) // 同时必须输出一个零!!! cout << c[i]; cout << endl; } return 0;}
0 0
- UVa 10106 Product
- UVa OJ 10106-Product
- Uva 10106 Product
- uva 10106 Product
- UVa 10106 - Product
- uva-10106 - Product
- UVA 10106 Product
- UVA 10106 - Product
- UVa 10106 - Product
- UVa 10106 - Product
- Uva 10106 - Product
- UVa 10106 - Product
- UVa - 10106 - Product
- UVA 10106 Product
- UVa 10106 - Product
- uva 10106 Product
- UVa 10106 Product (高精度)
- UVa 10106 - Product
- SecureCRT中使用上传下载文件工具rz和sz
- 风水如何提升领导运 沙发最宜紧靠客厅主位
- Android手机短信与通讯录存储位置
- STL vector中的rbegin方法(5)
- memcached refcount
- UVa-10106-Product
- RHEL6 install Chrome
- JavaScript的求模、取整、小数的取舍
- YUV格式详解
- hdu 4927 java程序
- The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files
- C++Vector用法
- 插入排序_3.希尔排序
- nginx作反向代理时的HTTP请求处理全过程解释