POJ 3673 Cow Multiplication

简介: Cow Multiplication Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13312   Accepted: 9307 Description Bessie is t...
Cow Multiplication
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 13312   Accepted: 9307

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 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

Source

分析:算是处理字符串吧!用两个数组去做,用一个数去计算它们的和即可!
下面给出AC代码:
 1 #include <algorithm>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <iostream>
 5 using namespace std;
 6 int main()
 7 {
 8     char a[10005],b[10005];
 9     int c[10005];
10     while(scanf("%s%s",&a,&b)!=EOF)
11     {
12         memset(c,0,sizeof(c));
13         int s=0;
14         int lena=strlen(a);
15         int lenb=strlen(b);
16         for(int i=0;i<lena;i++)
17         {
18             for(int j=0;j<lenb;j++)
19             {
20                 c[i]=(int)(a[i]-'0')*(int)(b[j]-'0');
21                 s+=c[i];
22             }
23         }
24         cout<<s<<endl;
25     }
26     return 0;
27 }

 

目录
相关文章
|
11月前
Light oj 1080 - Binary Simulation(树状数组区间更新点查询)
有一字符串只包含0和1,然后又m组操作,I L R是将从L到R的字符进行翻转操作0变为1、1变为0,Q x表示询问第x的字符。
33 0
uva442 Matrix Chain Multiplication
uva442 Matrix Chain Multiplication
36 0
UVA442 矩阵链乘 Matrix Chain Multiplication
UVA442 矩阵链乘 Matrix Chain Multiplication
|
人工智能
CodeForces-Kuroni and Impossible Calculation(思维+鸽巢原理)
CodeForces-Kuroni and Impossible Calculation(思维+鸽巢原理)
81 0
|
人工智能 BI
CodeForces - 1485D Multiples and Power Differences (构造+lcm)
CodeForces - 1485D Multiples and Power Differences (构造+lcm)
75 0
【欧拉计划第 5 题】最小公倍数 Smallest multiple
【欧拉计划第 5 题】最小公倍数 Smallest multiple
148 0
【欧拉计划第 5 题】最小公倍数 Smallest multiple
|
人工智能
Kuroni and Impossible Calculation——容斥原理-鸽笼原理-抽屉原理
题目描述 已知一个数组a[n],请计算式子:∏_{1≤i<j≤n}|ai−aj| 的值,其中1<=i,j<=n;我们可以认为,这一式子等价于 |a1−a2|⋅|a1−a3|⋅ … ⋅|a1−an|⋅|a2−a3|⋅|a2−a4|⋅ … ⋅|a2−an|⋅ … ⋅|an−1−an|
114 0
Kuroni and Impossible Calculation——容斥原理-鸽笼原理-抽屉原理
HDOJ 2028 Lowest Common Multiple Plus(n个数的最小公倍数)
HDOJ 2028 Lowest Common Multiple Plus(n个数的最小公倍数)
117 0
|
人工智能
poj2356:Find a multiple
题目链接: 【鸽巢原理+乱搞】 其实用不着开$map$ 一步最巧妙的转化是$……$前缀和。 反正本宝宝突发奇想就出来了。 首先,我们分类讨论。 1.当$∃i \in N_{+} $ 且 $i \in [1,n]$ 使 $a_{i} | n$ 则直接选这个数就好 2.没有以上那种特殊情况的话,我们记录前缀和$sum_{i}= \sum _{k=1}^{i} a_{k} (mod \ \ n)$ 然后又有两种情况。
1171 0
|
机器学习/深度学习 存储 人工智能