日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

不降的数字(51Nod-2499)

發布時間:2025/3/17 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 不降的数字(51Nod-2499) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目

小b有一個非負整數 N,她想請你找出 ≤N 的最大整數x,滿足x各個位數上的數字是不降的。也就是說,設x的十進制表示為 a1,a2,…,am,則對于任意 1≤i<m,ai≤ai+1。

輸入

輸入一個非負整數N。
0≤N≤10^9

輸出

輸出一個整數,表示答案

輸入樣例

332

輸出樣例

299

思路:從 n 開始枚舉,每次的 i 進行分解數位,滿足不降即可

源程序

#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #define EPS 1e-9 #define PI acos(-1.0) #define INF 0x3f3f3f3f #define LL long long const int MOD = 1E9+7; const int N = 100000+5; const int dx[] = {0,0,-1,1,-1,-1,1,1}; const int dy[] = {-1,1,0,0,-1,1,-1,1}; using namespace std; int a[N]; int main() {int n;scanf("%d",&n);for(int i=n; i>=1; i--) {int cnt=0;int temp=i;bool flag=true;while(temp) {//分解數位a[cnt++]=temp%10;temp/=10;if(cnt>=2 && a[cnt-1]>a[cnt-2]) {//不滿足不降的特性flag=false;break;}}if(flag) {//滿足不降的特性,輸出并終止枚舉printf("%d\n",i);break;}}return 0; }

?

新人創作打卡挑戰賽發博客就能抽獎!定制產品紅包拿不停!

總結

以上是生活随笔為你收集整理的不降的数字(51Nod-2499)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。