高精度乘法问题,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. 网页出现scanstyles does nothing in Webkit / Mozilla的解决方法

    今天ytkah要验证一些百度服务,那边的客服MM说她用ie浏览器打开网页出现"scanstyles does nothing in Webkit / Mozilla / Opera" ...

  2. 《暗黑世界GM管理后台系统》部署+功能说明文档

    http://www.9miao.com/product-10-1073.html <暗黑世界GM管理后台系统>部署+功能说明文档 <暗黑世界GM管理后台系统>部署+功能说明文 ...

  3. swift-基础部分

    变量常量,注释,分号,整数,浮点数.数值行类型转换,类型别名,波尔值,元组,可选,断言              let binaryInteger = 0b10001  let twoThousan ...

  4. WCF分布式开发步步为赢(11):WCF流处理(Streaming)机制

    WSE3.0框架提供了数据优化传输机制,WSE3.0构建Web服务安全(4):MTOM消息传输优化和文件上传.下载 疑问里进行了介绍.WCF同样也提供了流操作来支持大数据对象的传输和处理优化机制,今天 ...

  5. 三、Android NDK编程预备之Java jni入门创建C/C++共享库

    转自: http://www.eoeandroid.com/thread-264971-1-1.html 应网友回复,答应在两天前要出一篇创建C/C++共享库的,但由于清明节假期,跟朋友出去游玩,丢手 ...

  6. IDA 与VC 加载符号表

    将Windbg路径下的symsrv.yes 拷贝到ida 的安装目录,重新分析ntoskrnl.exe, 加载本地的符号表 添加环境变量  变量名:_NT_SYMBOL_PATH变量值:SRV*{$P ...

  7. FastJson与Gson小测试

    最近用到Json来传输数据,找到两个比较简单的工具 Gson 和 FastJson随便测试一下两个工具的效率~ 1 package com.json.fast; import java.util.Ar ...

  8. 测试in和or的执行时间

    declare @d datetime set @d=getdate() /*你的SQL脚本开始*/ SELECT * FROM T_KNOWLEDGE WHERE KNOWLEDGE_TYPE_OI ...

  9. ScriptManager.RegisterStartupScript方法和Page.ClientScript.RegisterStartupScript() 区别

    ScriptManager.RegisterStartupScript方法 如果页面中不用Ajax,cs中运行某段js代码方式可以是: Page.ClientScript.RegisterStartu ...

  10. 【poj3243-Clever Y】高次同余方程-拓展BabyStepGiantStep

    http://poj.org/problem?id=3243 题意:给定X,Z,K,求一个最小的Y满足XY mod Z = K. 关于拓展BSGS的详细解释我写了一篇博文:http://www.cnb ...