一、题目
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/93f2b3476b13f42512f6938f8dbd4e8a.png)
二、代码
class Solution
{
public:
int monotoneIncreasingDigits(int n)
{
int i,j;
int return_num=0;
vector<int> process_vector;
vector<int> temp_vector;
vector<int> bit_vector;
int temp_num;
int mode=1;
temp_num=n;
if(temp_num==0) return 0;
while(temp_num!=0)
{
temp_vector.push_back(temp_num%10);
temp_num=temp_num/10;
}
for(i=0;i<temp_vector.size();i++) std::cout<<" "<<temp_vector[i];
std::cout<<std::endl;
for(i=temp_vector.size()-1;i>=0;i--) process_vector.push_back(temp_vector[i]);
std::cout<<" process_vector "<<std::endl;
for(i=0;i<process_vector.size();i++) std::cout<<" "<<process_vector[i];
std::cout<<std::endl;
for(i=0;i<process_vector.size();i++) bit_vector.push_back(0);
for(i=process_vector.size()-1;i>=1;i--)
{
if(process_vector[i]>=process_vector[i-1])
{
bit_vector[i]=process_vector[i];
if(i==1) mode=0;
}
else
{
process_vector[i-1]--;
bit_vector[i-1]=process_vector[i-1];
for(j=i;j<bit_vector.size();j++) bit_vector[j]=9;
}
}
if(mode==0) bit_vector[0]=process_vector[0];
std::cout<<" bit_vector "<<std::endl;
for(i=0;i<bit_vector.size();i++) std::cout<<" "<<bit_vector[i];
std::cout<<std::endl;
return_num=bit_vector[0];
for(i=1;i<bit_vector.size();i++)
{
return_num=return_num*10;
return_num=return_num+bit_vector[i];
}
return return_num;
}
};
三、运行结果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/291fd590713642a7a60f3195eb1c8efd.png)