POJ 3673:Cow Multiplication
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 12210 | Accepted: 8509 |
Description
Bessie is tired of multiplying pairs of numbers the usual way, so she invented her own style of multiplication. In her style, A*B is equal to the sum of all possible pairwise products between the digits of A andB. For
example, the product 123*45 is equal to 1*4 + 1*5 + 2*4 + 2*5 + 3*4 + 3*5 = 54. Given two integers A and B (1 ≤ A, B ≤ 1,000,000,000), determine A*B in Bessie's style of multiplication.
Input
* Line 1: Two space-separated integers: A and B.
Output
* Line 1: A single line that is the A*B in Bessie's style of multiplication.
Sample Input
123 45
Sample Output
54
还是水题。。。字符串按位乘,再相加。
代码:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std; int main()
{
string m,n;
cin>>m>>n; int i,j,result=0;
for(i=0;i<m.length();i++)
{
for(j=0;j<n.length();j++)
{
result += (m[i]-'0')*(n[j]-'0');
}
}
cout<<result<<endl;
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 3673:Cow Multiplication的更多相关文章
- POJ 3318:Matrix Multiplication(随机算法)
http://poj.org/problem?id=3318 题意:问A和B两个矩阵相乘能否等于C. 思路:题目明确说出(n^3)的算法不能过,但是通过各种常数优化还是能过的. 这里的随机算法指的是随 ...
- POJ 3176:Cow Bowling
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13464 Accepted: 8897 Desc ...
- POJ 2184:Cow Exhibition(01背包变形)
题意:有n个奶牛,每个奶牛有一个smart值和一个fun值,可能为正也可能为负,要求选出n只奶牛使他们smart值的和s与fun值得和f都非负,且s+f值要求最大. 分析: 一道很好的背包DP题,我们 ...
- POJ 3673 Cow Multiplication
Cow Multiplication Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13312 Accepted: 93 ...
- POJ 3617 Best Cow Line(最佳奶牛队伍)
POJ 3617 Best Cow Line Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] FJ is about to t ...
- POJ 3268 Silver Cow Party 最短路—dijkstra算法的优化。
POJ 3268 Silver Cow Party Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbe ...
- Poj 3189 Steady Cow Assignment (多重匹配)
题目链接: Poj 3189 Steady Cow Assignment 题目描述: 有n头奶牛,m个棚,每个奶牛对每个棚都有一个喜爱程度.当然啦,棚子也是有脾气的,并不是奶牛想住进来就住进来,超出棚 ...
- POJ 3617 Best Cow Line ||POJ 3069 Saruman's Army贪心
带来两题贪心算法的题. 1.给定长度为N的字符串S,要构造一个长度为N的字符串T.起初,T是一个空串,随后反复进行下面两个操作:1.从S的头部删除一个字符,加到T的尾部.2.从S的尾部删除一个字符,加 ...
- POJ 3252:Round Numbers
POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...
随机推荐
- js 保留两位小数 input要求是数字框,
要求:input文本框只能输入数字,且只保留两位小数 问题:若设置input的 type="number" ,js处理部分若用到parseFloat方法处理,结果是string类 ...
- 小米xiaomi9 google play卡在检查信息
终于在今年淘汰掉用了三年的果6s,换了小米9 ,结果发现科学..上网后,可以正常打开google网页,却无法登陆,gmail也无法使用.一直卡在“正在核对信息”. 检查服务,小米9 全系列自带了谷歌框 ...
- Java对比两个数据库中的表和字段,写个冷门的东西
Java对比两个数据库中的表和字段,写个冷门的东西 转载的 来源网络 目前所在的项目组距离下个版本上线已经很近了,就面临了一个问题:开发人员在开发库上根据需要增加数据表.数据字段.或者变更了字段类型或 ...
- postgres 删除外部表
drop external table if exists tableName;
- springboot整合quartz并持久化到数据库
首先,这里的持久化是是如果当服务器宕机时,任务还在为我们保存.并且在启动服务器之后仍然可以自动执行 一.创建quartz 建表语句mysql的,quartz 2.3.0版本 DROP TABLE IF ...
- DB2的常用指令
注:大写的是固定的,小写的根据自己的实际情况 首先进入 命令窗口, win+r ---> 输入 db2cmd db2 1. 删除数据库 UNCATALOG DB db_name --db_nam ...
- phpstudy后门漏洞复现php5.2
前段时间phpstudy被人发现某些版本存在后门,许多人就这样被当作肉鸡长达两年之久 后门隐藏在程序自带的php的php_xmlrpc.dll模块 影响的版本:phpstudy2016和2018 在H ...
- JS写一个漂亮的音乐播放器
先放上效果图: 正如图中所展示的播放器那样,我们用HTML+CSS+JS将这个效果实现出来. HTML页面布局 <div class="music"> <div ...
- R 《回归分析与线性统计模型》page141,5.2
rm(list = ls()) library(car) library(MASS) library(openxlsx) A = read.xlsx("data141.xlsx") ...
- Redis详解(四)——删除策略
Redis详解(四)--删除策略 Redis中的数据特征 Redis是一种内存级数据库,所有数据均存放在内存中,内存中的数据可以通过TTL指令来获取其状态,当 key 不存在时,返回 -2 . 当 k ...