- A x B Problem
- 2017-02-09 18:02:10 @
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <list>
#include <cctype>
using namespace std;
int main ()
{
//freopen("xx.in","r",stdin);
//freopen("xx.out","w",stdout);
char a1[10001];
char b1[10001];
int a[10001];
int b[10001];
int c[20002];
int lena;
int lenb;
int lenc;
int i;
int j;
int x;
int p;
cin>>p;
for (int k=1;k<=p;k++)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
cin>>a1>>b1;
lena=strlen(a1);
lenb=strlen(b1);
for (i=0;i<=lena-1;i++) a[lena-i]=a1[i]-48;
for (i=0;i<=lenb-1;i++) b[lenb-i]=b1[i]-48;
for (i=1;i<=lena;i++)
{
x=0;
for (j=1;j<=lenb;j++)
{
c[i+j-1]=a[i]*b[j]+x+c[i+j-1];
x=c[i+j-1]/10;
c[i+j-1]%=10;
}
c[i+lenb]=x;
}
lenc=lena+lenb;
while (c[lenc]==0&&lenc>1)
{
lenc--;
}
for (i=lenc;i>=1;i--)
{
cout<<c[i];
}
cout<<endl;
}
//while (1);
return 0;
}
2 条评论
-
twd2 LV 9 MOD @ 2017-02-09 22:02:55
- 使用了事实上低效的iostream
- 除法次数过多
-
2017-02-09 19:50:00@
也许你可以先看看这道题的数据范围
- 1