UVA 10106-Product(大数乘法)

Product

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Submit Status

Description

 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

注意当为0的情况,一开始忽略了这种情况。当任一个为0的时候别忘了输出0

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char str1[1010],str2[1010];
char a[1010],b[1010],sum[1010];
int main()
{
    int len1,len2;
    int i,j;
    while (~scanf("%s",str1))
    {
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        memset(sum,0,sizeof(sum));
        len1= strlen(str1);
        for (i=len1-1;i>=0;i--)
            a[len1-i-1]=str1[i]-'0';
        scanf("%s",str2);
        len2=strlen(str2);
        for (i=len2-1;i>=0;i--)
            b[len2-i-1]=str2[i]-'0';
        for (i=0;i<len1;i++)
        {
            for(j=0;j<len2;j++)
                sum[i+j]+=a[i]*b[j];
            for (j=0;j<1010;j++)
                if (sum[j]>=10)
                {
                    sum[j+1]+=sum[j]/10;
                    sum[j]%=10;
                }
        }
        int flag=0;
        for(i=1010;i>=0;i--)
        {
            if(flag||sum[i])
            {
                flag=1;
                printf("%d",sum[i]);
            }
        }
        if(!flag)
            printf("0");
        printf("\n");
    }
    return 0;
}
时间: 2024-08-03 17:01:50

UVA 10106-Product(大数乘法)的相关文章

UVA 10106 Product (大数相乘)

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 c

uva 10106 Product(高精度大数乘法)

昨天刚写了个大数加法,今天又来了个大数乘法,其实解法差不多,只不过换成了好多个大数的相加而 已,看别人的算法其实跟我的也差不多,都是这个姿势.wa了一次,竟然忘了考虑0的情况,以后交题之前,都要判 断一下边缘数据,大数据和小数据,要不就是白白被扣时间啊 #include<stdio.h> #include<stdlib.h> #include<string.h> #include<algorithm> using namespace std; char a[

Uva-oj Product 大数乘法

Product Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description The problem is to multiply two integers X, Y. (0<=X,Y<10250) Input The input will consist of a set of pairs of lines. Each line in pair cont

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

UVA 10106 Product 高精度运算

J - Product Crawling in process... Crawling failed Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description  Product  The Problem The problem is to multiply two integers X, Y. (0<=X,Y<10250) The Input The

uva 10106 Product

//简单大数相乘,用java很简单 import java.util.Scanner; import java.math.BigInteger; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); BigInteger a,b; while(in.hasNext()){ a = in.nextBigInteger(); b = in.nextBigInteg

Product UVA 10106

题目: 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 shou

POJ 2389 Bull Math(大数乘法,还是Java好)

Bull Math Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14252   Accepted: 7350 Description Bulls are so much better at math than the cows. They can multiply huge integers together and get perfectly precise answers ... or so they say. F

最短的计算大数乘法的c程序

#include <stdio.h> char s[99],t[99]; int m,n; void r(int i,int c) { int j=0,k=i; while(k)c+=s[j++]*t[k---1]; if(i)r(i-1,c/10); printf("%d",c%10); } void main() { gets(s);gets(t); while(s[n])s[n++]-=48; while(t[m])t[m++]-=48; r(m+n-1,0); }

大数乘法

1027 大数乘法 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B (A,B的长度 <= 1000,A,B >= 0) Output 输出A * B Input示例 123456 234567 Output示例 28958703552 相关问题 大数加法 0 大数开平方 640 大数进制转换 320 大数除法 320 大数乘法 V2 80 代码: 1 #inclu