uva 10106 Product(高精度乘法)
来源:互联网 发布:淘宝店铺怎样快速升钻 编辑:程序博客网 时间:2024/05/29 07:49
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题目大意:两个数求积。
解题思路:高精度乘法。
#include<iostream>#include<string.h>using namespace std;#define N 62505struct bign{int len, s[N]; bign(){memset(s, 0, sizeof(s));len = 1;} bign operator = (const char *num){len = strlen(num);for (int i = 0; i < len; i++)s[i] = num[len - i - 1] - '0';return *this;} bign operator * (const bign &c){bign sum;sum.len = 0; for (int i = 0; i < len; i++){int g = 0;for (int j = 0; j < c.len; j++){int x = s[i] * c.s[j] + g + sum.s[i + j];sum.s[i + j] = x % 10;g = x / 10;}sum.len = i + c.len;while (g){sum.s[sum.len++] = g % 10;g = g / 10;}}return sum;}};int main(){char str1[N], str2[N];while (cin >> str1 >> str2){bign num1, num2, sum;num1 = str1;num2 = str2;sum = num1 * num2;int bo = 0;for (int i = sum.len - 1; i >= 0; i--){if (sum.s[i] || bo){bo = 1;cout << sum.s[i];}}if (bo == 0)cout << bo;cout << endl;memset(str1, 0, sizeof(str1));memset(str2, 0, sizeof(str2));}return 0;}
- uva 10106 Product(高精度乘法)
- uva 10106 Product(高精度大数乘法)
- UVA 10106 Product 高精度乘法
- UVa 10106 - Product 高精度乘法-
- UVA 10106 Product (高精度乘法)
- UVA 10106 Product 简单高精度乘法
- uva 424 Integer Inquiry(高精度加法模板) uva 10106 Product(高精度乘法模板)
- (高精度运算4.7.21)UVA 10106Product(大数乘法)
- UVa 10106 Product (高精度)
- Product - UVa 10106 高精度
- UVA 10106高精度乘法
- uva 10106 Product(大数乘法)
- UVA 10106 - Product(大数乘法)
- UVA 10106 Product(大数乘法)
- Uva 10106 Product (高精度相乘)
- UVA 10106 Product 高精度运算
- uva 10106 - Product 大数乘法
- UVA 10106-Product(大数乘法)
- 让3个div并排的经典实例
- Objective-C中的@class的用法
- HDU——2012——素数判定
- Rails中的增删改查
- HDU——2011 ——多项式求和
- uva 10106 Product(高精度乘法)
- DateAndTime.java
- inotify使用
- SG-UAP平台简介
- HDU——2010—— 水仙花数
- rails中模型的关联关系 一对一、一对多、多对多及named_scope
- Look and Say 序列的Java实现
- 修改Chrome浏览器默认背景颜色为豆沙绿护眼色
- JAVA中switch能否用在byte上?能否用在long上?能否用在string上?