#include <iostream> #include <string> #include <vector>//#include <stdlib.h>//#include <a Ssert.h> using namespace std; void Reverse_data (String &data) {Char temp = ' 0 '; int start=0; int End=data.size ()-1; ASSERT (Data.size () && start <= end); while (Start < end) {temp = Data[start]; data[start++] = Data[end]; data[end--] = temp; }} void Compute_value (String lhs,string rhs,string &result) {reverse_data (LHS); Reverse_data (RHS); int i = 0, j = 0, res_i = 0; int tmp_i = 0; int carry = 0; for (i = 0; I!=lhs.size (); ++i, ++tmp_i) {res_i = tmp_i; In each calculation, the bits of the result store need to be incremented for (j = 0; j!= rhs.size (); ++j) {carry + = (result[res_i]-' 0 ') + ( Lhs[i]-' 0 ') * (Rhs[j]-' 0 ');//note here that each calculation does not guarantee that the rounding of the previous calculation results is eliminated, and that the previous calculation is considered. result[res_i++] = (carry% 10 + ' 0 '); CarRy/= 10; } while (carry)//multiplier A calculation is complete, there may be some carry no processing {result[res_i++] = (carry% 10 + ' 0 '); Carry/= 10; }} for (int i=result.size () -1;i>=0;i--) {if (result[i]!= ' 0 ') break; else result[i]= ' # '; Result.pop_back ()} reverse_data (Result); } int Main () {string A, B; cin>>a>>b; A= "123"; b= "2"; String result (A.size () +b.size (), ' 0 '); Compute_value (A,b,result); cout<<result<<endl; 7system ("pause"); #include <stdlib.h> return 0; }
[String] Multiply trees