1 string mul(string str1,string str2)
2 {
3 vector<int> v_res(str1.size()+str2.size(),0);
4 string::size_type i,j;
5 vector<int>::size_type k,p;
6
7 reverse(str1.begin(),str1.end());
8 reverse(str2.begin(),str2.end());
9 for(i = 0; i != str1.size(); ++i)
10 {
11 for(j = 0; j != str2.size(); ++j)
12 {
13 v_res[i+j] += (str1[i]-‘0‘) * (str2[j] - ‘0‘);
14 }
15 }
16 for(k = 0; k != v_res.size() - 1; ++k)
17 {
18 v_res[k+1] += v_res[k] / 10;
19 v_res[k] = v_res[k] % 10;
20 }
21
22 for(p = v_res.size() - 1; p != -1; --p)
23 {
24 if(v_res[p] != 0) break;
25 }
26 if(p == -1) p = 0;
27
28 string s_res(p+1,‘0‘);
29 for(k = p; k != -1; --k) s_res[p-k] = char(v_res[k] + ‘0‘);
30
31
32 return s_res;
33
34 }