Given numbers represented as strings, return multiplication of the numbers as a string.
Note:the numbers can be arbitrarily large and is non-negative.
Given the number of two string representations, the product of the two numbers is required, and the product is represented by a string. Where the number represented by the string is non-negative.
It's rough, it's not elegant at all Qaq
stringMultiplystringNUM1,stringNUM2) { vector<string>Ans_temp;stringTemp///First calculates the product of the number of NUM1 represented by the number of digits represented by the num2, the product is represented by a string, and is stored in the Ans_temp for(inti = Num2.length ()-1, Count =0; I >=0; I--, count++) {intup =0;stringTemp for(intj = num1.length ()-1; J >=0; j--) {intLast = ((num2[i)-' 0 ') * (Num1[j]-' 0 ') +up)%Ten; Up = ((Num2[i]-' 0 ') * (Num1[j]-' 0 ') + up)/Ten; Temp.push_back (last +' 0 '); }if(UP) Temp.push_back (up +' 0 ');//Highest bit with roundingReverse (Temp.begin (), Temp.end ()); for(intK = count; K >0; k--) {Temp.push_back (' 0 ');//Low fill 0} reverse (Temp.begin (), Temp.end ()); Ans_temp.push_back (temp); temp =""; }intup =0;stringAnsintt =0;//Sum for(intj =0; J < Ans_temp.size (); J + +) { for(inti = t; I <ans_temp[j].length (); i++) {intA = up; for(intK = J; K < Ans_temp.size (); k++) {A + = (Ans_temp[k][i]-' 0 '); } up = A/Ten; A = a%Ten; Ans.push_back (A +' 0 '); } t = Ans_temp[j].length (); }if(UP) {Ans.push_back (up+' 0 '); } reverse (Ans.begin (), Ans.end ());if(ans[0] ==' 0 ')return "0";returnAns }
[Leetcode] Multiply Strings