UVa 10106 Product 【大数相乘】WA
虽然是错的代码,但是还是想贴出来,最开始WA发现是没有考虑到乘积为0的情况,后来把a*0,0*a,a*0---0(若干个0),0--0(若干个0)*a都考虑进去了;可是还是WA,实在不懂先留在这儿。
| 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
#include<stdio.h>
#include<string.h>
#define max 500
int panduan(char a[])
{
int tag,flag=1;
int i;
for(i=0;a[i]!='\0'&&flag;i++)
{
if(a[i]!='0')
{
flag=0;
}
}
if(flag)
{
if(i==1)
return 1;
else
return 2;
}
else
return 0;
}
int main()
{
int i,j;
int len1,len2,len;
int a[max],b[max],c[max];
char str1[max],str2[max];
while(~scanf("%s %s",&str1,&str2))
{
if(panduan(str1)==1||panduan(str2)==1)//判断两个相乘的数里面有没有'0'
{
printf("0\n");
}
else if(panduan(str1)==2||panduan(str2)==2)//判断两个相乘的数里面如果出现0---0(若干个),则不处理这组数据
{
printf("\n");
continue;
}
else
{ memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
len1=strlen(str1);
len2=strlen(str2);
for(i=0;i<len1;i++)
{
a[i]=str1[len1-i-1]-'0';
}
for(i=0;i<len2;i++)
{
b[i]=str2[len2-i-1]-'0';
}
for(i=0;i<len2;i++)
{
for(j=0;j<len1;j++)
c[i+j]+=b[i]*a[j];
}
len=i+j;
for(i=0;i<len;i++)
{
if(c[i]>=10)
{
c[i+1]+=c[i]/10;
c[i]=c[i]%10;
}
}
for(i=len;(c[i]==0)&&(i>=0);i--);
for(j=i;j>=0;j--)
printf("%d",c[j]);
printf("\n"); }
}
}
UVa 10106 Product 【大数相乘】WA的更多相关文章
- (高精度运算4.7.21)UVA 10106 Product(大数乘法)
package com.njupt.acm; import java.math.BigInteger; import java.util.Scanner; public class UVA_10106 ...
- UVA 10106 Product (大数相乘)
Product The Problem The problem is to multiply two integers X, Y. (0<=X,Y<10250) The Input The ...
- UVa 10106 Product
高精度乘法问题,WA了两次是因为没有考虑结果为0的情况. Product The Problem The problem is to multiply two integers X, Y. (0& ...
- UVA 10106 (13.08.02)
Product The Problem The problem is to multiply two integers X, Y. (0<=X,Y<10250) The Input T ...
- POJ 2389 Bull Math(水~Java -大数相乘)
题目链接:http://poj.org/problem?id=2389 题目大意: 大数相乘. 解题思路: java BigInteger类解决 o.0 AC Code: import java.ma ...
- 大数相乘算法C++版
#include <iostream> #include <cstring> using namespace std; #define null 0 #define MAXN ...
- java版大数相乘
在搞ACM的时候遇到大数相乘的问题,在网上找了一下,看到了一个c++版本的 http://blog.csdn.net/jianzhibeihang/article/details/4948267 用j ...
- Linux C/C++ 编程练手 --- 大数相加和大数相乘
最近写了一个大数相乘和相加的程序,结果看起来是对的.不过期间的效率可能不是最好的,有些地方也是临时为了解决问题而直接写出来的. 可以大概说一下相乘和相加的解决思路(当然,大数操作基本就是两个字符串的操 ...
- Karatsuba乘法--实现大数相乘
Karatsuba乘法 Karatsuba乘法是一种快速乘法.此算法在1960年由Anatolii Alexeevitch Karatsuba 提出,并于1962年得以发表.此算法主要用于两个大数相乘 ...
随机推荐
- 文件系统VFS数据结构(超级块 inode dentry file)(收集整理)
Linux虚拟文件系统四大对象: 1)超级块(super block) 2)索引节点(inode) 3)目录项(dentry) 4)文件对象(file) 一个进程在对一个文件进行操作时各种对象的引用过 ...
- 解读:20大5G关键技术
解读:20大5G关键技术 5G网络技术主要分为三类:核心网.回传和前传网络.无线接入网. 核心网 核心网关键技术主要包括:网络功能虚拟化(NFV).软件定义网络(SDN).网络切片和多接入边缘计算(M ...
- html中的meta标签属性
<!-- 声明文档使用的字符编码 --> <meta charset='utf-8'> <!-- 优先使用 IE 最新版本和 Chrome --> <meta ...
- [tyvj 1061] Mobile Service (线性dp 滚动数组)
3月15日第一题! 题目限制 时间限制 内存限制 评测方式 题目来源 1000ms 131072KiB 标准比较器 Local 题目描述 一个公司有三个移动服务员.如果某个地方有一个请求,某个员工必须 ...
- maven的依赖冲突时的原则
1.如图: 假设上图中的项目B引入了一个junit.jar架包是3.0的版本 项目D引入了一个junit.jar架包是4.0的版本,那么项目X引用的将会是4.0的版本 2.pom.xml排到最前面的架 ...
- Cocos2d切换场景出现的问题-error C2653: “***”不是类或命名空间名称
1,在开头引入头文件 2,在要引入的头文件中,去除以下代码: #ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__ #endif ...
- 2019-04-03 SQL Group By某列,预先对该列进行一个预处理,提炼出共有的信息,即关键字case when 列名什么条件 then 赋值 else 赋值 end as 新列名
select sum(发行金额) from( select PoolNameFormat,count(cast(ItemValue as decimal(19,4))) as 发行笔数,sum(cas ...
- 提高生产力:SpringMVC中,使用扩展数据类型TypedMap接收Web请求参数
在Web项目中,如果前端MVC框架使用的是SpringMVC,可以使用Map接收前端请求参数,比bean要方便很多. 尤其是SpringMVC和Mybatis一起用的时候,用Map大大减少了需要的be ...
- UVA11827 Maximum GCD
/* UVA11827 Maximum GCD https://vjudge.net/contest/153365#problem/V 数论 gcd 水题,然而读入比较坑 * */ #include ...
- nodejs-Sream
Stream 是一个抽象接口,Node 中有很多对象实现了这个接口.例如,对http 服务器发起请求的request 对象就是一个 Stream,还有stdout(标准输出). Node.js,Str ...