#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int t,a[15][405],a1[15][205],a2[15][205];
string sum1[15],sum2[15];
int main(){
cin>>t;
for(int i=0; i<t; i++){
cin>>sum1[i]>>sum2[i];
}
int len;
for(int i=0; i<t; i++){
int len1=sum1[i].size(),len2=sum2[i].size();
if(sum1[i][0]=='-'&&sum2[i][0]!='-'){
cout<<"-";
sum1[i]=sum1[i].substr(1,len1-1);
len1--;
}
else if(sum1[i][0]!='-'&&sum2[i][0]=='-'){
cout<<"-";
sum1[i]=sum1[i].substr(1,len2-1);
len2--;
}else if(sum1[i][0]=='-'&&sum2[i][0]=='-'){
sum1[i]=sum1[i].substr(1,len1-1);
sum2[i]=sum2[i].substr(1,len2-1);
len1--;
len2--;
}
for(int j=0;j<len2;j++){
a2[i][j]=sum2[i][len2-j-1]-'0';
}
for(int j=0; j<len1; j++){
a1[i][j]=sum1[i][len1-j-1]-'0';
}
for(int k=0; k<len1; k++){
for(int j=0; j<len2; j++){
a[i][j+k]+=a1[i][k]*a2[i][j];
}
}
len=len1+len2-1;
for(int j=0; j<len; j++){
a[i][j+1]+=a[i][j]/10;
a[i][j]%=10;
}
while(a[i][len]){
a[i][len+1]+=a[i][len]/10;
a[i][len]%10;
len++;
}
for(int j=len-1; j>=0; j--){
cout<<a[i][j];
}
cout<<endl;
}
return 0;
}
L.19.18 (习题4)A*B
最新推荐文章于 2024-08-20 19:00:09 发布