高精度乘法问题,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. iOS数组和字符串的转化

    NSMutableArray *components = [messageStr componentsSeparatedByString:@"*"] ; 反过来为 NSStrig ...

  2. Eclipse环境下配置spket中ExtJS提示

    使用eclipse编写extjs时,一定会用到spket这个插件,spket可以单独当作ide使用,也可以当作eclipse插件使用,我这里是当作eclipse的插件使用的,下面来一步步图解说明如何配 ...

  3. strncpy 和 strcpy的区别 (要抽时间重点看,未完待续)

    strcpy的实现: //GNU-C中的实现(节选): */ char* strcpy(char *d, const char *s) { char *r=d; while((*d++=*s++)); ...

  4. UVA 10943 How do you add? DP

    Larry is very bad at math — he usually uses a calculator, whichworked well throughout college. Unfor ...

  5. BZOJ 1143 1143: [CTSC2008]祭祀river 最长反链

    1143: [CTSC2008]祭祀river Description 在遥远的东方,有一个神秘的民族,自称Y族.他们世代居住在水面上,奉龙王为神.每逢重大庆典, Y族都会在水面上举办盛大的祭祀活动. ...

  6. Java IO(三)

    File File类的常见方法: 1.创建. boolean createNewFile():在指定位置创建文件,如果该文件已经存在,则不创建,返回false.和输出流不一样,输出流对象一建立就创建文 ...

  7. [RM HA 1] Cloudera CDH5 RM HA功能验证

    简介: 最新的Cloudera CDH5.0.0 beta版本已经支持RM的HA, 笔者为此简单验证了RM HA的功能. 后续将继续分析其HA的原理,以及其与社区RM HA的区别. 集群部属与RM f ...

  8. iOS开发——技术精华Swift篇&Swift 2.0和Objective-C2.0混编之第三方框架的使用

    swift 语言是苹果公司在2014年的WWDC大会上发布的全新的编程语言.Swift语言继承了C语言以及Objective-C的特性,且克服了C语言的兼容性问题.Swift语言采用安全编程模式,且引 ...

  9. android-exploitme(四):参数篡改

    今天我们来测试请求中参数的篡改,这个在web安全测试中是常用的,拦截请求包,修改参数,提交 1.  首先我们需要启动模拟器,并使用本机的代理(加上参数-partition-size的目的是为了可以往a ...

  10. 本博客不再更新,欢迎访问本人托管在GitHub上的博客:www.wshunli.com

    本博客不再更新. 欢迎访问本人托管在GitHub上的博客:www.wshunli.com