| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 781 人关注过本帖
标题:乘法问题
取消只看楼主 加入收藏
星火gavin
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:78
专家分:170
注 册:2011-11-5
结帖率:90.48%
收藏
已结贴  问题点数:20 回复次数:6 
乘法问题
奶牛的乘法查看 提交 统计 提问 时间限制: 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
星火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
星火gavin
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:78
专家分:170
注 册:2011-11-5
收藏
得分:0 
回复 9楼 beyondyf
哎,拿人家的手短呀,分不在话下,如果能帮我看看上面到底错在哪里啦就更感激不尽了。
2012-03-31 22:11
星火gavin
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:78
专家分:170
注 册:2011-11-5
收藏
得分:0 
回复 11楼 beyondyf
没问题,学习啦。
2012-03-31 22:55
星火gavin
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:78
专家分:170
注 册:2011-11-5
收藏
得分:0 
回复 11楼 beyondyf
太值啦,多谢版主啦,学习了不少呀。
2012-03-31 23:12
快速回复:乘法问题
数据加载中...
 
   



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

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