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 contains one multiplyer.

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

HINT

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char a[10000],b[10000];
int i,j,t1,c,t2;
while(cin>>a>>b)
{
int sum[10000]={0};
int x=strlen(a);
int y=strlen(b);
t1=9999;t2=9999;
for(i=x-1;i>=0;i--)
{
for(j=y-1;j>=0;j--)
sum[t1--]+=((a[i]-'0')*(b[j]-'0'));
t2--;
t1=t2;
}
c=0;
for(i=9999;i>=0;i--)
{
sum[i]+=c;
c=0;
if(sum[i]>9)
{
c=sum[i]/10;
sum[i]=sum[i]%10;
}
}
for(i=0;i<10000;i++)
{
if(sum[i]!=0)
break;
}
for(j=i;j<10000;j++)
cout<<sum[j];
cout<<endl;
}
return 0;
}

Product(大数相乘)的更多相关文章

  1. UVA 10106 Product (大数相乘)

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

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

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

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

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

  4. java版大数相乘

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

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

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

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

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

  7. leetcode 43 Multiply Strings 大数相乘

    感觉是大数相乘算法里面最能够描述.模拟演算过程的思路 class Solution { public String multiply(String num1, String num2) { if(nu ...

  8. Java 大数相乘、大数相加、大数相减

    思路来源:: https://blog.csdn.net/lichong_87/article/details/6860329 /** * @date 2018/6/22 * @description ...

  9. 华为上机测试题(大数相乘-java)

    PS:这个不是自己写的,测试OK,供参考. /** * 大数相乘 */ public class BigData { public static void main(String[] args) { ...

  10. 求解Catalan数,(大数相乘,大数相除,大数相加)

    Catalan数 卡塔兰数是组合数学中一个常在各种计数问题中出现的数列.以比利时的数学家欧仁·查理·卡塔兰(1814–1894)命名.历史上,清代数学家明安图(1692年-1763年)在其<割圜 ...

随机推荐

  1. android 传感器使用 Compass指南针的实现功能

    以下是指南针通过方向传感器而旋转实现. CompassDemo.java: package com.example.activity; import android.app.Activity; imp ...

  2. leetcode_question_85 Largest Rectangle in Histogram

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  3. #include <array>

    array是静态数组,在栈上,不可以变长 vector比array更常用 不需要变长,容量较小,用array 需要变长,容量较大,用vector 1 array 1 array新数组 //std::a ...

  4. python-认识Socket[入门篇]

    什么是socket 网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket.socket通常也称作"套接字",用于描述IP地址和端口,是一个通信链 ...

  5. 链表-Reverse Linked List

    /** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * } ...

  6. Java程序在向mysql中插入数据的时候出现乱码

    今天在往数据库中插入数据的时候中文字符在数据库中就出现了乱码?网上有各种说法,但是适合我的,最终解决我的问题的只有下面一种! 在创建数据库的时候,注意设置编码方式. CREATE DATABASE ` ...

  7. BZOJ 3669: [Noi2014]魔法森林( LCT )

    排序搞掉一维, 然后就用LCT维护加边MST. O(NlogN) ------------------------------------------------------------------- ...

  8. 在C#调用C++的DLL方法(一)生成非托管dll

    C#与C/C++相比,前者的优势在于UI,后者的优势在于算法,C++下的指针虽然恶心,若使用得当还是相当方便的,最重要的问题是,市面上很多流行的开发工具库,几乎没有不支持C++的,但全面支持C#只能说 ...

  9. Html页面加回滚

    <div class="top-box"> <img src=" class="youlink-img" /><br / ...

  10. leetcode 31. Next Permutation(字典序的下一个)

    描述: Implement next permutation, which rearranges numbers into the lexicographically next greater per ...