| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 781 人关注过本帖
标题:乘法问题
只看楼主 加入收藏
星火gavin
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:78
专家分:170
注 册:2011-11-5
结帖率:90.48%
收藏
已结贴  问题点数:20 回复次数:15 
乘法问题
奶牛的乘法查看 提交 统计 提问 时间限制: 1000ms 内存限制: 10000kB
描述
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.
输入
The first line of input gives the number of test cases, 1 ≤ t ≤ 100.
 Each test case contains two integers A and B.
输出
Output for each test case a line with the A*B in Bessie's style of multiplication.
样例输入
2
123 45
1 12
样例输出
54
3
一道练习,我的想法很简单就是循环取余将数放入数组中在进行乘法运算,不过没有完成总觉得缺点什么?找找高手帮帮吧
搜索更多相关主题的帖子: determine products invented 
2012-03-29 23:01
zhangxiangD
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:39
专家分:119
注 册:2011-12-20
收藏
得分:0 
看不懂,说清楚点
2012-03-29 23:09
C_戴忠意
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:2
帖 子:575
专家分:1349
注 册:2011-10-21
收藏
得分:0 
你把代码贴上来...要不然怎么知道那里有问题

编程之路定要走完……
2012-03-29 23:10
小赵q1
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:4
帖 子:492
专家分:777
注 册:2011-8-26
收藏
得分:0 
全是英文表示看不懂,如果试过很多次都不能AC可以把代码贴出来,大家帮你看看哪里出问题了,也可以看看有没有简单点的方法,看你最后一句话的意思好像是有思路也做了就是不能通过,好想看看你的代码是什么样子的。
2012-03-30 06:13
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
奶牛贝斯,一看就是USACO的题目。
拿到题不要着急做,先分析一下。
这题直接按题意做也能通过,因为规模很小,只是个练习题。
但简单化简一下就会看出其结果就是两个数各位和的积。
所以在这个环节只需要做一次乘法就够了。

重剑无锋,大巧不工
2012-03-30 08:17
星火gavin
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:78
专家分:170
注 册:2011-11-5
收藏
得分:0 
回复 2楼 zhangxiangD
其实就是先输入数据个数,如样例里的2
然后输入123 45 算起来就是 1*4+2*4+3*4+1*5+2*5+3*5=54
下一个同理 1 12 就是1*1+1*2=3
2012-03-30 21:34
星火gavin
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:78
专家分:170
注 册:2011-11-5
收藏
得分:0 
回复 3楼 C_戴忠意
#include <stdio.h>
int main()
{
    int a[101][2]={0},b[101]={0},k=0,c[101]={0},m=0,j,n,l,r;
    int t,i,sum=0;
    scanf("%d",&t);
    for(i=1;i<=t;i++)
    {
        for(j=0;j<=1;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
    for(i=1;i<=t;i++)
    {   
        while(a[i][0]!=0)
        {
            b[k++]=a[i][0]%10;
            a[i][0]=a[i][0]/10;
        }
        while(a[i][1]!=0)
        {        
            c[m++]=a[j][1]%10;
            a[j][1]=a[j][1]/10;
        }
        for(n=0;n<=k;i++)
        {
            for(l=0;l<=1;l++)
            {
            sum=sum+b[n]*c[l];
            }
        }
        printf("%d\n",sum);
    }
    for(j=0;j<k;j++)
    {
        printf("%d",b[j]);
    }
}
2012-03-30 22:09
星火gavin
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:78
专家分:170
注 册:2011-11-5
收藏
得分:0 
回复 5楼 beyondyf
还是不太明白
2012-03-30 22:24
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
呵呵,突然想尝试做赏金猎人。
把20分加到这个帖子上,送你一段诠释我上面算法的代码。

重剑无锋,大巧不工
2012-03-31 14:20
星火gavin
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:78
专家分:170
注 册:2011-11-5
收藏
得分:0 
回复 9楼 beyondyf
哎,拿人家的手短呀,分不在话下,如果能帮我看看上面到底错在哪里啦就更感激不尽了。
2012-03-31 22:11
快速回复:乘法问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011828 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved