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 ...
随机推荐
- Ckeditor 中一些核心的对象的作用
1.CKEditor CKEditor对象用于掌管全局,他是一个单例对象,管理着所有实例化了的编辑框. 通过replace方法创建编辑框实例. 2.CKEditor.editor 表示一个编辑框实例, ...
- python笔记1
1.python中的语句块是用缩进表示,并不像C类语言中用{}表示语句块,还有就是语句块的开始貌似是用:表示,然后C类语言中()在python中用"空格"表示了,例如python中 ...
- c#知识库同步的总结
C#知识库下载地址: http://www.51aspx.com/Code/FileCollector 新版下载地址:http://pan.baidu.com/s/1P3Hk 对于这一款平时用来收集知 ...
- POJ 2140
#include<iostream> #include<stdio.h> using namespace std; int main() { int num; int i; i ...
- 定制CentOS (Redhat AS 5.1)安装盘
CentOS(Redhat)提供了一套完整的自动化安装机制,利用该机制,我们可以自己定制无人值守的自动安装光盘,也可以进行系统裁减,甚至可以以CentOS为基础制作自己软件系统的系统安装盘.以下全部内 ...
- 关于SIGPIPE导致的程序退出
http://www.cppblog.com/elva/archive/2008/09/10/61544.html 收集一些网上的资料,以便参考: http://blog.chinaunix.net/ ...
- Android 核心分析 之七Service深入分析
Service深入分析 上一章我们分析了Android IPC架构,知道了Android服务构建的一些基本理念和原理,本章我们将深入分析Android的服务.Android体系架构中三种意义上服务: ...
- 谈谈三层架构中Model的作用
Model又叫实体类,这个东西,大家可能觉得不好分层.包括我以前在内,是这样理解的:UI<-->Model<-->BLL<-->Model<-->DAL ...
- 一步步来配置安卓开发环境ADTBundle
前提 安装JDK,并且要正确配置环境变量. 特别要注意安装配置完后,CMD命令行窗口里输入 java 和 javac 查看是否有内容输出,若提示找不到命令就是你JDK配置错误了 至于如何配置JDK看这 ...
- wordpress模块无法拖拽/显示选项点击无反应
问题:wordpress模块无法拖拽/显示选项点击无反应,还有编辑器的全屏什么的都用不了,按F12查看了console,提示很多jQuery is not defined... 解决方法:把wp-in ...