水题求调
查看原帖
水题求调
541254
BugGod楼主2023/10/27 20:46

样例1输出57,样例2输出50。0pts。

#include<bits/stdc++.h>
using namespace std;
#define int long long
int x,k,ans1,ans2,maxx;
vector<int>n;
int power(int x,int y)
{
	if(y==0)return 1;
	if(y==1)return x;
	int kk=power(x,y>>1);
	return kk*kk*power(x,y&1); 
}
void thefirst()
{
	maxx=-1;
	while(x)n.push_back(x%10),x/=10;
	for(auto i:n)maxx=max(maxx,i);
	for(int k=0;k<n.size();k++)ans1+=power(maxx,k);
}
signed main()
{
	cin>>x>>k;
	if(k==0)
	{
		thefirst();
		cout<<ans1;
	}
	else
	{
		thefirst();
		ans2=ans1;
		for(int i=0;i<n.size();i++)
		{
			if(ans2-maxx*power(10,i)>=x)ans2-=maxx*power(10,i);
		}
		cout<<ans2;
	}
	return 0;
}
2023/10/27 20:46
加载中...