文章标题 POJ 3673 : Cow Multiplication (水)
来源:互联网 发布:linux elinks命令 编辑:程序博客网 时间:2024/04/30 22:18
Cow Multiplication
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 and B. 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
题意:重新定义*这个符号,A*B表示A中每个位上的数乘以B中每个数字,然后相加得到答案。
分析:可以直接输入两个数字,用字符串输入,然后枚举每个字符,然后转化成相应的数字相乘。
代码:
#include<iostream>#include<string>#include<cstdio>#include<cstring>#include<vector>#include<math.h>#include<map>#include<queue> #include<algorithm>using namespace std;const int inf = 0x3f3f3f3f;string a,b; int main (){ while (cin>>a>>b){ int len_a=a.length(); int len_b=b.length(); int ans=0; for (int i=0;i<len_a;i++){ for (int j=0;j<len_b;j++){ ans+=((a[i]-'0')*(b[j]-'0')); } } cout<<ans<<endl; } return 0;}
0 0
- 文章标题 POJ 3673 : Cow Multiplication (水)
- POJ 3673 Cow Multiplication(水~)
- poj 3673 Cow Multiplication
- POJ 3673 Cow Multiplication
- POJ 3673 Cow Multiplication
- POJ - 3673 Cow Multiplication
- POJ 3673:Cow Multiplication
- POJ 3673 Cow Multiplication
- poj 3673 Cow Multiplication(水题)
- POJ 3673 Cow Multiplication G++
- 文章标题poj 3278 Catch That Cow(bfs实现)
- 文章标题 POJ 3278 : Catch That Cow(BFS)
- 文章标题 POJ 3268 : Silver Cow Party (最短路--spfa)
- 文章标题 Silver Cow Party
- 文章标题 Catch That Cow
- Cow Multiplication
- 文章标题poj 1132: Border(模拟)
- 文章标题 poj 1837: Balance(dp)
- Android博客周刊专题之#插件化开发#
- javascript基础:Date对象
- 二叉树【链表实现】基础练习
- yum install XX 常见问题和命令
- linux字符设备驱动
- 文章标题 POJ 3673 : Cow Multiplication (水)
- 微信小程序——-会滑动的顶部tab选项卡
- Android中签名原理和安全性分析之META-INF文件讲解
- UVA 11624 Fire! bfs
- TestNG中DataProvider的用法
- javascript的正则表达式中加入变量
- css入门教程(一)
- JavaScript 多线程概念的含义
- SDWebImage源码解读之NSData+ImageContentType