题解 | #特殊乘法#
特殊乘法
https://www.nowcoder.com/practice/a5edebf0622045468436c74c3a34240f
//描述
//写个算法,对2个小于1000000000的输入,求结果。
//特殊乘法举例:123 * 45 = 1*4 +1*5 +2*4 +2*5 +3*4+3*5
//输入描述:
//两个小于1000000000的数
//输出描述:
//输入可能有多组数据,对于每一组数据,
//输出Input中的两个数按照题目要求的方法进行运算后得到的结果。
#include <string>
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){
string str1,str2;
while(cin>>str1>>str2){
int answer = 0;
for(int i=0;i<str1.size();++i){
for(int j=0;j<str2.size();++j){
answer += (str1[i] - '0')*(str2[j] - '0');
//如果s[0]是字符0~9,则表示将该字符变为对应的数字(int 型)
//例如:'9'-'0'=9;
}
}
printf("%d\n",answer);
}
return 0;
}

