51nod 1770 数数字

在这里插入图片描述
输入样例
2
3 3 9 10
3 3 0 10
输出样例
10
0

思路总结:n个a乘以b,总结起来一共有三种情况:
a×b没有进位,结果所有的位数一致(a×b<10)
a×b有进位,且进位和下一位乘积相加也有进位((a×b<10)&&(a×b)%10+(a×b)/10>=10)。
a乘b有进位,但进位和下一位乘积相加没有进位((a×b<10)&&(a×b)%10+(a×b)/10<10)。
特别注意n=1情况要单独处理

#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
int main()
{
	vector<int> vec;
	int a, b, d, t;
	long long int n;
	cin >> t;
	while (t--)
	{
		cin >> a >> b >> d>>n ;
		map<int,long long int>map1;
		if (a*b < 10)
		{
			if (a*b == d)
				map1[a*b] = n;
		}
		else
		{ 
			int temp = a * b;
			int ans = temp % 10;
			int bns = temp / 10;
			int cns = bns + ans;
			if (n == 1)
			{
				map1[ans] += 1;
				map1[bns] += 1;
				cout << map1[d] << endl;
				continue;
			}
			if (cns < 10)
			{
				map1[ans] += 1;
				map1[bns] += 1;
				map1[cns] += n - 1;
			}
			else
			{   
				int t1 = cns % 10;
				int t2 = cns / 10;
				map1[ans] += 1;
				map1[t2 + bns] += 1;
				map1[t1] += 1;
				map1[t1 + t2] += n - 2;

			}
		}
		cout << map1[d] << endl;
	}
	
	getchar();
	getchar();

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值