POJ3673Cow Multiplication(水)
来源:互联网 发布:mac 安装sass 编辑:程序博客网 时间:2024/06/15 20:07
Cow Multiplication
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 13399 Accepted: 9371
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
Source
USACO 2008 February Bronze
题目大意:要求把两个1e9以内的数,每一位互相乘然后输出
解题思路:不断的除和模
#include<iostream> #include<cstdio> #include<stdio.h> #include<cstring> #include<cstdio> #include<climits> #include<cmath> #include<vector> #include <bitset> #include<algorithm> #include <queue> #include<map> using namespace std;int a[50], b[50];int i, j, k;long long int n, m, ans;int main(){cin >> n >> m;k = 10;ans = 0;memset(a, -1, sizeof(a));memset(b, -1, sizeof(b));while (n!=0){a[++ans] = n%k;n /= k;}k = 10;ans = 0;while (m!=0){b[++ans] = m%k;m /= k;}for (i=1;;i++){if (a[i] == -1){n = i - 1;break;}}for (i = 1;; i++){if (b[i] == -1){m = i - 1;break;}}ans = 0;for (i = 1; i <= n; i++){for (j = 1; j <= m; j++){ans += a[i] * b[j];}}cout << ans << endl;}
0 0
- POJ3673Cow Multiplication(水)
- Multiplication
- POJ---3318-Matrix Multiplication 水
- POJ 1651 Multiplication Puzzle 区间dp(水
- POJ 3673 Cow Multiplication(水~)
- CodeForces - 577A Multiplication Table(水)
- 文章标题 POJ 3673 : Cow Multiplication (水)
- PKU_ACM_3673_Cow Multiplication
- multiplication puzzle
- Multiplication Puzzle
- Matrix Multiplication
- Multiplication Puzzle
- Matrix Multiplication
- Matrix Multiplication
- Matrix Multiplication
- Matrix multiplication
- Matrix multiplication
- Multiplication Puzzle
- 商人小鑫
- NavigationView 选中、默认、按下样式
- 初学php连接mysql (loading)
- 排序算法总结(二)
- C# 连接Oracle 11g,(注:可少走弯路)
- POJ3673Cow Multiplication(水)
- LeetCode-273. Integer to English Words
- Leetcode 11. Container With Most Water The Solution of Python
- 装船问题
- jquery常用事件
- 515. Find Largest Value in Each Tree Row
- C++ 多继承和虚继承的内存布局
- linux下nfs配置
- myeclipse最常用的快捷键