POJ 3673:Cow Multiplication
2015-07-09 10:23
471 查看
Cow Multiplication
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
Sample Output
还是水题。。。字符串按位乘,再相加。
代码:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 12210 | Accepted: 8509 |
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; }
相关文章推荐
- 学堂在线c++进阶 编程题10-3
- mysql日志设置
- 批处理taskkill运行结束不掉程序以及停留问题
- 各种编码的由来及编码见转换
- 完整类库列表struts2.0
- jquery插件封装
- 阿里巴巴开源项目:分布式数据库同步系统otter(解决中美异地机房) - agapple - ITeye技术网站
- 安卓动态调试方法
- 如何让你的Apache支持include文件解析和支持shtml的相关配置
- volatile 是啥
- 算法基础:正整数指定规则排序问题(Golang实现)
- 其原因可能是堆被损坏 这说明exe中或它所加载的任何 DLL 中有 Bug
- 编写websocket时需要导入包
- VS2013 GDI+显示png
- 小型倒计时定时器:innerText的浏览器兼容问题
- 简单运行Nginx + PHP
- Android批量图片加载经典系列——afinal框架实现图片的异步缓存加载
- RTMP协议抓包详解
- 查看Android系统给APP分配的最大堆栈
- clone DEMO(be aware of list mutability)