模板
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> using namespace std; void cheng( char *a, char *b, char *sum ) { int temp[2500]; int lena,lenb,l; lena=strlen(a); lenb=strlen(b); int len = lena + lenb; for (int i=0;i<=len;i++ ) temp[i]=0; for (int i=lena-1;i>=0;i-- ) { l=lena-1-i; for (int j=lenb-1;j>=0;j-- ) { temp[l]=(b[j]-'0')*(a[i]-'0')+temp[l]; l++; } } while (temp[l]==0) l--; for (int i=0;i<=l;i++ ) { temp[i+1]+=temp[i]/10; temp[i]=temp[i]%10; } if ( temp[l+1]!=0 ) l++; while ( temp[l]/10!=0 ) { temp[l+1]+=temp[l]/10; temp[l]=temp[l]%10; l++; } if ( temp[l]==0 ) l--; int i=0; while ( l>=0 ) { sum[i]=temp[l]+'0'; i++; l--; } sum[i]='\0'; } int main() { char a[10000],b[10000],sum[200000]; cin>>a>>b; cheng(a,b,sum); puts(sum); return 0; }
时间: 2024-10-23 17:14:14