POJ 3673 Cow Multiplication

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 }
复制代码

 

posted @   Angel_Kitty  阅读(215)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述
点击右上角即可分享
微信分享提示
哥伦布
14°
14:09发布
哥伦布
14:09发布
14°
大雨
南风
3级
空气质量
相对湿度
93%
今天
中雨
14°/19°
周日
中雨
5°/19°
周一
1°/11°