- #include <iostream>
- #include <sstream>
- #include <string>
- #include <cmath>
- using namespace std;
- int string_to_num(string k)//string字符串变整数型例如str=“1234”,转换为整数的1234.
- {
- int back;
- stringstream instr(k);
- instr>>back;
- return back;
- }
- long long ff(string x,string y)//递归函数
- {
- int s = x.size();
- string A,B,C,D;
- if( s > 1)
- {
- A = x.substr(0,s/2);
- B = x.substr(s/2,s-1);
- C = y.substr(0,s/2);
- D = y.substr(s/2,s-1);
- }
- int na = string_to_num(A);
- int nb = string_to_num(B);
- int nc = string_to_num(C);
- int nd = string_to_num(D);
- long long result = 0;
- if( s == 2)
- {
- result = (na*10+nb) * (nc*10+nd);
- }
- else{
- result = ff(A,C)*pow(10.0,s)+((na-nb)*(nd-nc)+ff(A,C)+ff(B,D))*(long long)(pow(10.0,s/2))+ff(B,D);
- }
- return result;
- }
- int main()
- {
- string A,B,C,D;
- string num1,num2;
- long long r;
- cin>>num1>>num2;
- int size = num1.size();
- A = num1.substr(0,size/2);
- B = num1.substr(size/2,size-1);
- C = num2.substr(0,size/2);
- D = num2.substr(size/2,size-1);
- cout<<A<<” “<<B<<” “<<C<<” “<<D<<endl;
- r = ff(num1,num2);
- cout<<num1<<” “<<“*”<<” “<<num2<<” “<<“=”<<” “<<r<<endl;
- return 0;
- }