You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
836 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
/*
一个正整数如果任何一个数位不大于右边相邻的数位,则称为一个数位递增的数,
例如1135是一个数位递增的数而1024不是一个数位递增的数。
给定正整数 n请问在整数 11 至 n 中有多少个数位递增的数?
*/
using namespace std;
int n, cnt;
bool iSDiZeng(int t) {
//哨兵
int x = 10; //这里定义x为10是为了便于将个位数的大小与t作比较
//个位数永远小于10
while (t) {
if (t % 10 > x) return false;
x = t % 10; // x一直在更新
t /= 10; // n分解出一个数便舍去一个数
}
return true;
}
int main() {
cin >> n;
for (int i = 11; i <= n; i++)
if (iSDiZeng(i)) cnt++;
cout << cnt << endl;
return 0;
}