利用str[i]-"0"来实现字符之间的乘法
#include <iostream> using namespace std; int main() { string num1; string num2; while (cin >> num1 >> num2) { int res = 0; for (int i = 0; i < num1.length(); i++) { for (int j = 0; j < num2.length(); j++) { res = res + (num1[i] - '0') * (num2[j] - '0'); } } cout << res << endl; } }