3 solutions
-
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int temp = n; int num = 0; //位数 while(temp){ num++; temp/=10; } int ans = (num-1)*9; //如果是n位数,那么n-1位的范围内的优美数字就已经确定了 ///接下来判断n位数范围有几个优美数字 //1. 例如数字8848,就有1111,2222,3333,4444,5555,6666,7777 这七个优美数 //2. 可以发现如果是四位数,优美数之间增量就是1111;如果是三位数,增量为111 int add = 1; //第一步需要先把增量算出来 for(int i=1;i<num;i++){ add*=10; add+=1; } int temp2=add; //从1111开始 for(temp2=add;temp2<=n;temp2+=add){ //递增判断,注意增量 ans+=1; } cout<<ans<<endl; return 0; }
Information
- ID
- 2886
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- # Submissions
- 71
- Accepted
- 26
- Uploaded By