1. 程式人生 > >【POJ】Cow Multiplication(水題)

【POJ】Cow Multiplication(水題)

i++ targe tar AS names += include stream org

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; }

【POJ】Cow Multiplication(水題)