虽然是错的代码,但是还是想贴出来,最开始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的更多相关文章

  1. (高精度运算4.7.21)UVA 10106 Product(大数乘法)

    package com.njupt.acm; import java.math.BigInteger; import java.util.Scanner; public class UVA_10106 ...

  2. UVA 10106 Product (大数相乘)

    Product The Problem The problem is to multiply two integers X, Y. (0<=X,Y<10250) The Input The ...

  3. UVa 10106 Product

    高精度乘法问题,WA了两次是因为没有考虑结果为0的情况.  Product  The Problem The problem is to multiply two integers X, Y. (0& ...

  4. UVA 10106 (13.08.02)

     Product  The Problem The problem is to multiply two integers X, Y. (0<=X,Y<10250) The Input T ...

  5. POJ 2389 Bull Math(水~Java -大数相乘)

    题目链接:http://poj.org/problem?id=2389 题目大意: 大数相乘. 解题思路: java BigInteger类解决 o.0 AC Code: import java.ma ...

  6. 大数相乘算法C++版

    #include <iostream> #include <cstring> using namespace std; #define null 0 #define MAXN ...

  7. java版大数相乘

    在搞ACM的时候遇到大数相乘的问题,在网上找了一下,看到了一个c++版本的 http://blog.csdn.net/jianzhibeihang/article/details/4948267 用j ...

  8. Linux C/C++ 编程练手 --- 大数相加和大数相乘

    最近写了一个大数相乘和相加的程序,结果看起来是对的.不过期间的效率可能不是最好的,有些地方也是临时为了解决问题而直接写出来的. 可以大概说一下相乘和相加的解决思路(当然,大数操作基本就是两个字符串的操 ...

  9. Karatsuba乘法--实现大数相乘

    Karatsuba乘法 Karatsuba乘法是一种快速乘法.此算法在1960年由Anatolii Alexeevitch Karatsuba 提出,并于1962年得以发表.此算法主要用于两个大数相乘 ...

随机推荐

  1. js 目录树

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  2. oracle AWR详解

    原文地址:https://blog.csdn.net/elvis_lfc/article/details/52326148 啥是AWR? =============================== ...

  3. utf8_general_ci、utf8_unicode_ci和utf8_bin的区别(转载)

    例如: CREATE DATABASE IF NOT EXISTS redmine DEFAULT CHARSET utf8 COLLATE utf8_general_ci; CREATE DATAB ...

  4. PySimpleGUI 的第一个桌面软件

    最近学习了python风格的GUI模块,寻思着既然学了,就要学以致用,花了点时间,写了下面这个 简历软件.后面,可以通过接口 获取提交的数据,传到数据库里与网页交互.此软件我已经打包成 exe软件,直 ...

  5. php ob缓存

    用PHP的ob_start();控制您的浏览器cache Output Control 函数可以让你自由控制脚本中数据的输出.它非常地有用,特别是对于:当你想在数据已经输出后,再输出文件头的情况.输出 ...

  6. php 文件夹 与 文件目录操作

    php文件夹操作函数 string basename ( string path [, string suffix] )给出一个包含有指向一个文件的全路径的字符串,本函数返回基本的文件名.如果文件名是 ...

  7. Flume 读取实时更新的日志文件

    http://blog.csdn.net/bright60/article/details/50728306 我用了第一种方法. 1. 日志文件每天roate一个新文件 a)  方案一 There i ...

  8. pl/sql输入括号后卡顿的解决方式

    pl/sql输入括号后卡顿的解决方式 学习了:https://zhidao.baidu.com/question/298275368.html 工具->首选项->用户界面->代码助手 ...

  9. 图像算法研究---Adaboost算法具体解释

    本篇文章先介绍了提升放法和AdaBoost算法.已经了解的可以直接跳过.后面给出了AdaBoost算法的两个样例.附有详细计算过程. 1.提升方法(来源于统计学习方法) 提升方法是一种经常使用的统计学 ...

  10. Cocos2dx之使用UI库结合cocostudio

    使用cocostudio的UI编辑器编辑好UI界面,导出UI文件,直接在cocos2dx中使用.通过tag或者name来获取到UI控件 1.编辑ui界面,直接用模板然后拖几个控件过去 2.cocos2 ...