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年得以发表.此算法主要用于两个大数相乘 ...
随机推荐
- 05--C语言运算符优先级和ASCII码表
- struts中日期处理以及文件下载
日期处理 对于jsp提交的基本数据类型和日期格式为yyyy-MM-dd的自动转换为相应的 对于其它的日期格式需要自定义转换器 局部类型转换器 1,写转换器类(继承StrutsTypeConverter ...
- 序列模型(3)---LSTM(长短时记忆)
摘自https://www.cnblogs.com/pinard/p/6519110.html 一.RNN回顾 略去上面三层,即o,L,y,则RNN的模型可以简化成如下图的形式: 二.LSTM模型结构 ...
- 关于高校表白APP的用户模板和用户场景
用户模板一: 用户名 小明 性别,年龄 男,20岁 用户状况 单身,在校大学生 生活爱好 喜欢打篮球,唱歌 典型场景 希望找到一个心仪的可以走到最后的姑娘 典型描述 交友 用户比例 ? 用户场景一 ...
- 【ACM-ICPC 2018 南京赛区网络预赛 J】Sum
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 线性筛求出每个数的最小质因子x for 从1-n 对于i,它的最小质因子为x 考虑i=ab 如果i能被x^3整除 那么这x怎么分配给 ...
- JavaScript中的XMLDOM对象
测试: demo.xml中的内容: js文件内容: window.onload=function(){ //var v=returnXMLDOM(); //v.loadXML('<root> ...
- java+selenium自动化遇到confirm弹窗,出现NoAlertPresentException: no alert open
//操作js的confirm弹窗,bool控制是否点击确定,true为点击确定,false为点击取消 public static void OperaterJSOfConfirm(WebDriver ...
- POJ 1236 Network of Schools 强连通图
Description A number of schools are connected to a computer network. Agreements have been developed ...
- 第一篇、Android Supersu 权限管理定制,隐藏过滤权限,指定APP最高权限
近期有个需求,在预装ROM的时候,须要权限,可是又不同意全部的应用都有权限,仅仅同意自己的应用有最高的权限(当然没有系统签名情况下). 所以.编译了CM 提取了supersu进行了二次定制,让他进行权 ...
- Oracle 中UNDO与REDO的差别具体解释
一 为了更清楚的看出2者差别,请看下表: UNDO ...