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年得以发表.此算法主要用于两个大数相乘 ...
随机推荐
- C# treeView 控件
#region --基础 ////设置目录树 ////添加根节点 //treeView1.Nodes.Add("0000000"); ////添加子节点 ////treeView1 ...
- 应用二:Vue之ElementUI Form表单校验
(注:本文适用于有一定Vue基础或开发经验的读者,文章就知识点的讲解不一定全面,但却是开发过程中很实用的) 表单校验是前端开发过程中最常用到的功能之一,根据个人的工作经验总结在此对表单校验功能的基 ...
- 代码检查工具sonarqube介绍及使用
亲测有效 环境:springboot+gradle+jdk1.8+sonarqube7.4 一.说明: SonarQube为静态代码检查工具,采用B/S架构,帮助检查代码缺陷,改善代码质量,提高开发速 ...
- Tab切换效果(修改)
前几天我写了这个切换效果,但是是只传一个值的函数,经过各位大牛的指点发现还是有些问题的,于是经过我不懈的努力,完善了代码: 传递多个参数替代函数里面包含事件这个问题: html代码: <div ...
- Linux Shell脚本编程-基础1
概述: shell脚本在Linux系统管理员的运维工作中非常重要.shell脚本能够帮助我们很方便的管理服务器,因为我们可以指定一个任务计划,定时的去执行某一个脚本以满足我们的需求.本篇将从编程基础 ...
- 02.OOP面向对象-1.面向对象介绍
1.面向对象编程介绍 面向对象(object-oriented ;简称: OO) 至今还没有统一的概念 我这里把它定义为: 按人们 认识客观世界的系统思维方式,采用基于对象(实体) 的概念建立模型,模 ...
- 基于Tags的简单内容推荐的实现
原来为了简单方便,自己小网站上的文章页的相关内容推荐就是从数据库里随机抽取数据来填充一个列表,所以一点相关性都没有,更本没有办法引导用户去访问推荐内容. 算法选择 如何能做到相似内容的推荐呢,碍于小网 ...
- Mysql提升大数据导入速度的绝妙方法
一.对于Myisam类型的表,可以通过以下方式快速的导入大量的数据. ALTER TABLE tblname DISABLE KEYS; loading the data A ...
- 最大团&稳定婚姻系列
[HDU] 1530 Maximum Clique 1435 Stable Match 3585 maximum shortest distance 二分+最大团 1522 Marriage is ...
- hdu 4079简单贪心
#include<stdio.h> #include<string.h> #define ll __int64 #define N 11000 struct node { in ...