高精度乘,和我们小学的手算一样
这里只需要注意进位就行
#include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<iostream> using namespace std; char s1[10005],s2[10005]; int ll[10005]; int len1,len2,len3; int main() { freopen("t.in","r",stdin); freopen("t.out","w",stdout); memset(ll,0,sizeof(ll)); scanf("%s",s1); scanf("%s",s2); len1 = strlen(s1); len2 = strlen(s2); for(int i=0; i<=(len1-1)/2; i++) { char c = s1[i]; s1[i] = s1[len1-i-1]; s1[len1-i-1] = c; } for(int i=0; i<=(len2-1)/2; i++) { char c = s2[i]; s2[i] = s2[len2-i-1]; s2[len2-i-1] = c; } for(int i=0; i<len1; i++) { for(int j=0; j<len2; j++) { ll[j+i] += (s1[i]-'0')*(s2[j]-'0'); } } len3 = len1+len2-1; for(int i=0; i<len3; i++) { while(ll[i]>=10) { ll[i]-=10; ll[i+1]++; } } if(ll[len3]>0) len3++; int i = len3-1; while(i>0) { if(ll[i]!=0) break; i--; } len3 = i; for(int i=len3; i>=0; i--) { printf("%d",ll[i]); } return 0; }