UVa 10106 Product
高精度乘法问题,WA了两次是因为没有考虑结果为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
12
12
2
222222222222222222222222
Sample Output
144
444444444444444444444444
AC代码:
//#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; const int maxn = ;
char a[maxn], b[maxn];
int x[maxn], y[maxn], mul[maxn * + ];
void Reverse(char s[], int l); int main(void)
{
#ifdef LOCAL
freopen("10106in.txt", "r", stdin);
#endif while(gets(a))
{
gets(b);
int la = strlen(a);
int lb = strlen(b);
memset(mul, , sizeof(mul));
memset(x, , sizeof(x));
memset(y, , sizeof(y));
Reverse(a, la);
Reverse(b, lb);
int i, j;
for(i = ; i < la; ++i)
x[i] = a[i] - '';
for(i = ; i < lb; ++i)
y[i] = b[i] - ''; for(i = ; i < lb; ++i)
{
int s = , c = ;
for(j = ; j < maxn; ++j)
{
s = y[i] * x[j] + c + mul[i + j];
mul[i + j] = s % ;
c = s / ;
}
} for(i = maxn * + ; i >= ; --i)
if(mul[i] != )
break;
if(i < )
cout << ;
else
{
for(; i >=; --i)
cout << mul[i];
}
cout << endl;
}
return ;
}
//用来反转数组
void Reverse(char s[], int l)
{
int i;
char t;
for(i = ; i < l / ; ++i)
{
t = s[i];
s[i] = s[l - i -];
s[l - i -] = t;
}
}
代码君
UVa 10106 Product的更多相关文章
- UVa 10106 Product 【大数相乘】WA
虽然是错的代码,但是还是想贴出来,最开始WA发现是没有考虑到乘积为0的情况,后来把a*0,0*a,a*0---0(若干个0),0--0(若干个0)*a都考虑进去了:可是还是WA,实在不懂先留在这儿. ...
- UVA 10106 Product (大数相乘)
Product The Problem The problem is to multiply two integers X, Y. (0<=X,Y<10250) The Input The ...
- (高精度运算4.7.21)UVA 10106 Product(大数乘法)
package com.njupt.acm; import java.math.BigInteger; import java.util.Scanner; public class UVA_10106 ...
- uva 993 Product of digits (贪心 + 分解因子)
Product of digits For a given non-negative integer number N , find the minimal natural Q such tha ...
- UVA 10106 (13.08.02)
Product The Problem The problem is to multiply two integers X, Y. (0<=X,Y<10250) The Input T ...
- UVa 993: Product of digits
这道题很简单.先将N用2,3,5,7(即10以内的素数)分解因数(需要先特殊判断N不为1),然后将可以合并的因数合并(如2*2合并成4,)这样求得的结果位数会减少,大小肯定会小一些.具体实现见代码. ...
- uva 10106
尝试一下java 的大数类 import java.util.*; import java.io.*; import java.math.BigInteger; public class Main { ...
- UVA 12532-Interval Product(BIT)
题意: 给n个数字的序列,C v p 把v位上的数字置成p , S l r代表求区间[l,r]各数字相乘得数的符号,对于每个S输出所得符号(’+‘,’-‘,’0‘) 分析: 开两个数组表示区间负数的个 ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
随机推荐
- swappiness
在ubuntu 里面,swappiness的值的大小对如何使用swap分区是有着很大的联系的.swappiness=0的时候表示最大限度使用物理内存,然后才是 swap空间,swappiness=10 ...
- PageControl(弹性滚动)
使用网上源码KYAnimatedPageControl self.pageControl = [[KYAnimatedPageControl alloc]initWithFrame:CGRec ...
- Codeforces Round #260 (Div. 2) A~C
题目链接 A. Laptops time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputo ...
- C#保留小数位数
1.System.Globalization.NumberFormatInfo provider = new System.Globalization.NumberFormatInfo(); prov ...
- poj 2425 A Chess Game 博弈论
思路:SG函数应用!! 代码如下: #include<iostream> #include<cstdio> #include<cmath> #include< ...
- WCF分布式开发步步为赢(5)服务契约与操作重载
继上一节WCF分布式开发步步为赢系列的(4):WCF服务可靠性传输配置与编程开发,本节我们继续学习WCF分布式开发步步为赢的第(5)节:服务契约与操作重载.这里我们首先讲解OOP面向对象的编程中方法重 ...
- Linux网络编程1——小端模式与大端模式
数据存储优先顺序的转换 计算机数据存储有两种字节优先顺序:高位字节优先(称为大端模式)和低位字节优先(称为小端模式).内存的低地址存储数据的低字节,高地址存储数据的高字节的方式叫小端模式.内存的高地址 ...
- Chrome 开发工具指南
Chrome 开发工具指南 谷歌 Chrome 开发工具,是基于谷歌浏览器内含的一套网页制作和调试工具.开发者工具允许网页开发者深入浏览器和网页应用程序的内部.该工具可以有效地追踪布局问题,设置 Ja ...
- 叠罗汉III之推箱子
有一堆箱子,每个箱子宽为wi,长为di,高为hi,现在需要将箱子都堆起来,而且为了使堆起来的箱子不到,上面的箱子的宽度和长度必须小于下面的箱子.请实现一个方法,求出能堆出的最高的高度,这里的高度即堆起 ...
- APM (应用性能管理)
在信息科学和系统控制领域,APM是用来监控和管理应用软件是否有效运行的.APM通过监测和分析应用的表现去保证软件应用的良好运行,APM已经商用. 基本定义 APM = Application Perf ...