题解 | #特殊乘法#(死算方法)
特殊乘法
https://www.nowcoder.com/practice/a5edebf0622045468436c74c3a34240f
#include <iostream> using namespace std; int getD(int n){ int d = 0; while(n > 0){ n = n / 10; d++; } return d; } int multi(int n1,int n2) { int r = 0, d1 = getD(n1), d2 = getD(n2), i = 0, j = 0; int* m1 = new int[d1]; int* m2 = new int[d2]; while(n1 > 0){ m1[i] = n1 % 10; n1 = n1 / 10; i++; } while(n2 > 0){ m2[j] = n2 % 10; n2 = n2 / 10; j++; } for(i = 0;i < d1; i++){ for(j = 0;j < d2; j++){ r = r + m1[i]*m2[j]; } } delete [] m1; delete [] m2; return r; } int main() { int n1, n2; while (cin >> n1 >> n2) { cout << multi(n1, n2) << endl; } return 0; }