大数乘法a*b

Description

Given two positive integers a and b, please help us calculate a*b.

Input

The first line of the input is a positive integer T. T is the number of test cases followed.
Each test case contain two integer a,b (0<=a<=10^100, 0<=b<=10,000) given in one line.

Output

The output of each test case should consist of one line, contain the result of a*b.

Sample Input
Copy sample input to clipboard
2
2 7
1234567890123456 100
Sample Output
14
123456789012345600


这是一道大数乘法。只不过,a是大数,b是可以用int存储的数。
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	int b,num[102];
	int t;
	cin>>t;
	for(int h=0;h<t;h++)
	{
		cin>>a>>b;
		int size=a.size();
		for(int i=0;i<size;i++)
		{
			num[size-i-1]=a[i]-'0';
		}
		
		int carry=0,result[120];
		memset(result,0,sizeof(result));
		for(int i=0;i<size;i++)
		{
			result[i]=num[i]*b+carry;
			carry=result[i]/10;
			result[i]=result[i]%10;
		}
		result[size]=carry;
		
		int len=size+4;
		
		while(len>=0&&result[len]==0)
		{
			len--;
		}
		if(len<0) cout<<"0";
		else {
			for(int i=len;i>=0;i--)
			{
				cout<<result[i];
			}
		}
		
		cout<<endl;
	}
	return 0;
}




你可能感兴趣的:(大数乘法a*b)