UVa - 10106 - Product
来源:互联网 发布:包月网络电话卡 编辑:程序博客网 时间:2024/05/17 18:14
题目大意:
求两个数的乘积,用高精度写。但要注意结果为0 的情况!
#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>#define N 1010using namespace std;char str1[N], str2[N];int ans[N];int main(){int i, j;while (scanf("%s", str1) != EOF){memset(ans, 0, sizeof(ans));reverse(str1, str1 + strlen(str1));scanf("%s", str2);reverse(str2, str2 + strlen(str2));for (i = 0; i < strlen(str1); i ++){for (j = 0; j < strlen(str2); j ++){ans[i + j] += (str1[i] - '0') * (str2[j] - '0');if (ans[i + j] > 9){ans[i + j + 1] += ans[i + j] / 10;ans[i + j] %= 10;}}}for (j = 1009; j >= 0; j --){if (ans[j] != 0){break;}if (j == 0){printf("0");}}for (i = j; i >= 0; i --){printf("%d", ans[i]);}printf("\n");}return 0;}
Product
The Problem
The problem is to multiply two integers X, Y. (0<=X,Y<10250)
The Input
The input will consist of a set of pairs of lines. Each line in pair contains one multiplyer.
The Output
For each input pair of lines the output line should consist one integer the product.
Sample Input
12122222222222222222222222222
Sample Output
144444444444444444444444444
- 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
- ext 几个常用的控件
- eclipse 使用技巧备忘录
- Maya 2013 语言切换
- 通过Canvas及File API缩放并上传图片
- Camera 运行流程 与 Preview过程分析
- UVa - 10106 - Product
- NSThread应用
- 您的计算机上的 Office 2003 安装已损坏,安装程序无法继续。请删除或修复 Office 2003 产品并重新运行
- 如何使用ftrace进行内核调试
- c#写webservice快速链接到数据库的方法Linq to Sql简单操作
- 最常用的6种代码搜索引擎
- LINUX/UNIX 文件状态标志的 与或非 操作
- 常见的可以创建窗口的Windows API小结
- 分配页面