高精度乘法问题,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的更多相关文章

  1. UVa 10106 Product 【大数相乘】WA

    虽然是错的代码,但是还是想贴出来,最开始WA发现是没有考虑到乘积为0的情况,后来把a*0,0*a,a*0---0(若干个0),0--0(若干个0)*a都考虑进去了:可是还是WA,实在不懂先留在这儿. ...

  2. UVA 10106 Product (大数相乘)

    Product The Problem The problem is to multiply two integers X, Y. (0<=X,Y<10250) The Input The ...

  3. (高精度运算4.7.21)UVA 10106 Product(大数乘法)

    package com.njupt.acm; import java.math.BigInteger; import java.util.Scanner; public class UVA_10106 ...

  4. uva 993 Product of digits (贪心 + 分解因子)

      Product of digits  For a given non-negative integer number N , find the minimal natural Q such tha ...

  5. UVA 10106 (13.08.02)

     Product  The Problem The problem is to multiply two integers X, Y. (0<=X,Y<10250) The Input T ...

  6. UVa 993: Product of digits

    这道题很简单.先将N用2,3,5,7(即10以内的素数)分解因数(需要先特殊判断N不为1),然后将可以合并的因数合并(如2*2合并成4,)这样求得的结果位数会减少,大小肯定会小一些.具体实现见代码. ...

  7. uva 10106

    尝试一下java 的大数类 import java.util.*; import java.io.*; import java.math.BigInteger; public class Main { ...

  8. UVA 12532-Interval Product(BIT)

    题意: 给n个数字的序列,C v p 把v位上的数字置成p , S l r代表求区间[l,r]各数字相乘得数的符号,对于每个S输出所得符号(’+‘,’-‘,’0‘) 分析: 开两个数组表示区间负数的个 ...

  9. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

随机推荐

  1. vs2010把项目资源打包成系统资源

      把wav格式的音频做成系统资源,根据条件播放相应的音频  System.Media.SoundPlayer spOne = new System.Media.SoundPlayer();      ...

  2. Unity3D 将 Unity 嵌入WPF中的一些研究笔记

     一. 在 WPF 中使用 WebBrowser,直接打开 WebPlayer.html 以这种方式有一个问题是. 无法在 WebBrowser 的上面 放置其它的控件, 在运行时,都不会显示 . 以 ...

  3. Java开发WebService的几种方法--转载

    webservice的应用已经越来越广泛了,下面介绍几种在Java体系中开发webservice的方式,相当于做个记录. 1.Axis2 Axis是apache下一个开源的webservice开发组件 ...

  4. CMD窗口正确显示UTF-8字符

     Go语言教程 http://yiibai.com/go/  CMD窗口正确显示UTF-8字符 http://www.360doc.com/content/13/0424/13/2569758_280 ...

  5. 2014多校第五场1010 || HDU 4920 Matrix multiplication(矩阵乘法优化)

    题目链接 题意 : 给你两个n*n的矩阵,然后两个相乘得出结果是多少. 思路 :一开始因为知道会超时所以没敢用最普通的方法做,所以一直在想要怎么处理,没想到鹏哥告诉我们后台数据是随机跑的,所以极端数据 ...

  6. 未能正确加载“Microsoft.VisualStudio.Editor.Implementation.EditorPackage”

    VS2012启动/加载项目出问题 未能正确加载“Microsoft.VisualStudio.Editor.Implementation.EditorPackage, Microsoft.Visual ...

  7. 在DECIMAL(m,n)的设置中,整数的位数不能大于(m-n)

    关于DB2的DECIMAL类型 创建表的时用的是DECIMAL(13,2),我认为它为13个整数位数+2为有效数字,因为在打印银行交易的FORM时遇到了难题.输出和建表的长度不一样,我们以为它会打印出 ...

  8. Linux下ps -ef和ps aux的区别及格式详解

    Linux下显示系统进程的命令ps,最常用的有ps -ef 和ps aux.这两个到底有什么区别呢?两者没太大差别,讨论这个问题,要追溯到Unix系统中的两种风格, System V风格和BSD 风格 ...

  9. Girls: different perspectives to consider

    Girls: different perspectives to consider成为极品女人的十大要素The point of articles such as these isn't to dic ...

  10. hive-学习笔记

    1.hive模糊搜索表  show tables like '*name*'; 2.查看表结构信息  desc formatted table_name;  desc table_name; 3.查看 ...