Product
来源:互联网 发布:全自动编程软件 编辑:程序博客网 时间:2024/04/27 15:01
Product
The problem is to multiply two integers X, Y . (0 X; Y < 10250)
Input
The input will consist of a set of pairs of lines. Each line in pair contains one multiplyer.
Output
For each input pair of lines the output line should consist one integer the product.
Sample Input
12
12
2
222222222222222222222222
Sample Output
144
444444444444444444444444
大意:
计算大数据的乘法运算
要点:
使用数组进行存储
注意*0的情况
代码:
#include <iostream>#include <string>using namespace std;string t1, t2;int x[1000], y[1000], ans[1000];void modulo(){for (int i = 0; i < 999; i++){ans[i + 1] += ans[i] / 10;ans[i] = ans[i] % 10;}}void product(int m, int n){for (int i = 0; i < n; i++){for (int j = 0; j < m; j++){ans[j + i] += y[i] * x[j];modulo();}}}int main(){while (cin >> t1 >> t2){int flag = true;int leng1 = t1.length();int leng2 = t2.length();if (leng2 > leng1){string temp = t1;t1 = t2;t2 = temp;}leng1 = t1.length();leng2 = t2.length();for (int i = leng1 - 1, j = 0; i >= 0; i--, j++)x[j] = t1[i] - '0';for (int i = leng2 - 1, j = 0; i >= 0; i--, j++)y[j] = t2[i] - '0';product(leng1, leng2);for (int i = 999; i >= 0; i--){if (ans[i] == 0 && flag)continue;flag = false;cout << ans[i];}if (flag)cout << "0";cout << endl;for (int i = 0; i < 1000; i++){ans[i] = 0;x[i] = 0;y[i] = 0;}}}
0 0
- product
- Product
- Product
- Product
- Product
- Max product
- 2510: Product
- 10106 - Product
- JOJ2510:Product
- Product line
- 10106 - Product()
- uva10106 - Product
- 10106 - Product
- 10106 - Product
- 5309 Product
- Product Management
- 10106 - Product
- uva Product
- json数据语法格式
- PAT (Advanced Level) 1051. Pop Sequence (25) 是否为pop序列,模拟栈的操作
- java实现选择排序
- 关于android ui开发处理的问题
- ICMP协议应用--ping和traceroute
- Product
- POJ 1111----F - 广搜 基础
- 栈和队列常见题型(java版)
- DirectUI界面编程(五)WindowImplBase的使用
- 牛腩新闻发布系统(7)——总结
- unity编辑器对对象属性的编辑
- mysql的alter table 命令
- MediaElement教程
- MyEclipse快捷键大全