Cow Multiplication
http://poj.org/problem?id=3673
题意:输入两个数A B,比如123和45 然后算123*45这个运算是指1*4 + 1*5 + 2*4 + 2*5 + 3*4 + 3*5 = 54.
思路:水题。
#include<iostream> #include<cmath> #include<cstring> using namespace std; typedef long long ll; const int inf = 0x3f3f3f3f; int main() { char a[20], b[20]; cin >> a >> b; int i, j, sum = 0, la, lb; la = strlen(a); lb = strlen(b); for(i = 0; i < la; i++) { for(j = 0; j < lb; j++) { sum += ((a[i] - ‘0‘) * (b[j] - ‘0‘)); } } cout << sum << endl; return 0; }
原文地址:https://www.cnblogs.com/Kohinur/p/8893287.html
时间: 2024-10-26 22:13:46