POJ 2389
1 #include <iostream> 2 #include <algorithm> 3 #include <string> 4 #define MAXN 300 5 using namespace std; 6 7 int tem[MAXN]; 8 9 void big_int_mul(string a,string b,string & ans); 10 11 int main() 12 { 13 //freopen("acm.acm","r",stdin); 14 string a; 15 string b; 16 string ans; 17 cin>>a>>b; 18 big_int_mul(a,b,ans); 19 cout<<ans<<endl; 20 } 21 22 void big_int_mul(string a,string b,string & ans) 23 { 24 int len_1 = a.length(); 25 int len_2 = b.length(); 26 int len = a.length() + b.length(); 27 int i; 28 int j; 29 for(i = 0; i < len_1; ++ i) 30 { 31 for(j = 0; j < len_2; ++ j) 32 { 33 tem[i+j+1] += (a[i]-'0')*(b[j] - '0'); 34 } 35 } 36 for(i = len - 1; i > 0; -- i) 37 { 38 if(tem[i] >= 10) 39 { 40 tem[i-1] += tem[i]/10; 41 tem[i] %= 10; 42 } 43 } 44 j = 0; 45 while(tem[j] == 0) 46 { 47 ++ j; 48 } 49 50 for(; j < len; ++ j) 51 { 52 ans += char(tem[j]+'0'); 53 } 54 }