Codeforces Round #549 (Div. 2) B. Nirvana

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_41608020/article/details/88994196

当K为0时,表示前面的数字没了,所以应该返回1

#include <bits/stdc++.h>
using namespace std;
int solve(int k)
{
	//k=0表示前面的数字不存在
	if (k == 0)
		return 1;
	if (k < 10)
		return k;
	return max(solve(k / 10) * (k % 10), solve(k / 10 - 1) * 9);
}
int main() 
{
	int n;
	scanf("%d", &n);
	printf("%d", solve(n));
}        

猜你喜欢

转载自blog.csdn.net/qq_41608020/article/details/88994196