深夜水题第二弹,高精度乘法。
论三分钟打完。。
#include<bits/stdc++.h>
char s1[101],s2[101];
int l1,l2,l3;
int a[101],b[101],c[101];
int main()
{
freopen("in.txt","r",stdin);
gets(s1),gets(s2);
while (s1[l1]>='0'&&s1[l1]<='9')l1++;
while (s2[l2]>='0'&&s2[l2]<='9')l2++;
for (int i=1;i<=l1;i++)a[l1-i+1]=s1[i-1]-'0';
while (!a[l1])l1--;
for (int i=1;i<=l2;i++)b[l2-i+1]=s2[i-1]-'0';
while (!b[l2])l2--;
for (int i=1;i<=l1;i++)
for (int j=1;j<=l2;j++)
c[i+j-1]+=a[i]*b[j];
for (int i=1;i<=l1+l2+2;i++)
while (c[i]>9)
c[i]-=10,c[i+1]++;
for (l3=l1+l2+3;l3;l3--)if (c[l3]) break;
for (int i=l3;i>=1;i--)printf("%d",c[i]);
return 0;
}