计算机机试题:数位拆解(取余)

题目描述:

写个算法,对2个小于1000000000的输入,求结果。

特殊乘法举例:123 * 45 = 1*4 +1*5 +2*4 +2*5 +3*4+3*5

输入:

 两个小于1000000000的数

输出:

 输入可能有多组数据,对于每一组数据,输出Input中的两个数按照题目要求的方法进行运算后得到的结果。

样例输入:
123 45
样例输出:

54

代码如下:

#include<stdio.h>
#include<stdlib.h>
int main()
{
	int m;int n;
	while(scanf_s("%d%d", &m,&n)!=EOF)
	{
		int buf1[11], buf2[11];
		int count1=0;
		int count2=0;
		while(m!=0)
		{
			buf1[count1] = m%10;
			//printf("%d ", buf1[count1]);
			m = m/10;
			count1++;
		}
		while(n!=0)
		{
			buf2[count2] = n%10;
			n = n/10;
			count2++;
		}
		int sum =0;
		for(int i=0; i<count1; i++)
		{
			for(int j=0; j<count2; j++)
			{
				sum = sum + buf1[i] * buf2[j];
			}
		}
		printf("%d\n", sum);
	}
	return 0;
}
		


思路:这个题也是个水题,比较简单。

猜你喜欢

转载自blog.csdn.net/xckkcxxck/article/details/80988867