码迷,mamicode.com
首页 > 其他好文 > 详细

【POJ】Cow Multiplication(水题)

时间:2018-04-20 22:02:29      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:str   ace   输入   题意   http   bsp   namespace   main   stream   

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(水题)

标签:str   ace   输入   题意   http   bsp   namespace   main   stream   

原文地址:https://www.cnblogs.com/Kohinur/p/8893287.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!