加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

poj 2389 BullMath(大数乘法)

发布时间:2020-12-14 03:12:58 所属栏目:大数据 来源:网络整理
导读:Bull Math Time Limit: ?1000MS ? Memory Limit: ?65536K Total Submissions: ?14987 ? Accepted: ?7707 Description Bulls are so much better at math than the cows. They can multiply huge integers together and get perfectly precise answers ... or
Bull Math
Time Limit:?1000MS ? Memory Limit:?65536K
Total Submissions:?14987 ? Accepted:?7707

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. Farmer John wonders if their answers are correct. Help him check the bulls' answers. Read in two positive integers (no more than 40 digits each) and compute their product. Output it as a normal number (with no extra leading zeros).?

FJ asks that you do this yourself; don't use a special library function for the multiplication.

Input

* Lines 1..2: Each line contains a single decimal number.

Output

* Line 1: The exact product of the two input lines

Sample Input

22222222221111
2222222222

Sample Output

12345679011110987654321

Source

USACO 2004 November

tips:水题
#include<iostream>
#include<cstring>
#include<string>


using namespace std;

string s1,s2;
char ans[88];
void multi()
{
	int ans[88];
	int a[88],b[88],lena=0,lenb=0;
	memset(a,sizeof(a));memset(b,sizeof(b));
	memset(ans,sizeof(ans));
	for(int i=s1.size()-1;i>=0;i--)a[lena++]=s1[i]-'0';
	for(int i=s2.size()-1;i>=0;i--)b[lenb++]=s2[i]-'0';
	
	for(int j=0;j<lenb;j++)
	for(int i=0;i<lena;i++)
	{
		ans[i+j]+=b[j]*a[i];
		ans[i+j+1]+=ans[i+j]/10;
		ans[i+j]=ans[i+j]%10;
	}
	int flag=0;
	for(int i=80;i>=0;i--)
	{
		if(ans[i]!=0||flag==1){
			flag=1;cout<<ans[i];
		}
	}
	cout<<endl;
}
int main()
{
	
	while(cin>>s1>>s2)
	{
		multi();
	}	
	
	return 0;
 } 

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读