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年得以发表.此算法主要用于两个大数相乘 ...
随机推荐
- Python中生成器,迭代器,以及一些常用的内置函数.
知识点总结 生成器 生成器的本质就是迭代器. 迭代器:Python中提供的已经写好的工具或者通过数据转化得来的. 生成器:需要我们自己用Python代码构建的 创建生成器的三种方法: 通过生成器函数 ...
- [POI2007]MEG-Megalopolis 树状数组 + dfs序前缀和 好题
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const ...
- Nginx部署静态资源(及root与alias区别)
root目录与alias目录的区别Nginx路径location配置中,使用root目录与alias目录的区别 1)alias指定的目录是准确的,即location匹配访问的path目录下的文件直接是 ...
- asyncio 自动跳出长时间堵塞的 task
https://www.cnblogs.com/ywhyme/p/10660411.html 的升级版 可以知道当前是卡在哪一个 task 甚至是多少行 import asyncio import o ...
- [POJ 3621] Sighting Cows
01分数规划的基本裸题. 因为路线一定是个环,所以找个最优比率生成环即可 二分一个比值,check一下即可. #include <queue> #include <cstdio> ...
- assound.conf
pcm.!dmix {type dmixipc_key 5678293ipc_key_add_uid yesslave {pcm "hw:0,0"period_time 0peri ...
- 基于vue的可视化编辑器
https://github.com/jaweii/Vue-Layout https://github.com/L-Chris/vue-design https://github.com/fir ...
- JAVA基础总结【面试】
前言 近间陆续面试了不少的求职的前(JAVA).后(WEB)端开发人员,包括实习生.应届毕业生.一两年工作经验的.也有三四年工作经验的,也算见过了比较多的开发人员,想在这里做个总结,本次主要讲一讲面试 ...
- js中“使用”el表达式
在说相关内容前,一定要先熟悉jsp运行原理: http://blog.csdn.net/lmsnju/article/details/4813488 http://hi.baidu.com/mingf ...
- MSMQ如何设置事务特性