最近蒜头君喜欢上了U型数字,所谓U型数字,就是这个数字的每一位先严格单调递减,后严格单调递增。比如 212212 就是一个U型数字,但是 333333, 9898, 567567, 3131331313,就是不是U型数字。
现在蒜头君问你,[1,100000][1,100000] 有多少U型数字?
提示:请不要输出多余的符号。
#include <bits/stdc++.h>
using namespace std;string numToString(int n)
{
stringstream ss;
ss << n;
return ss.str();
}
int main()
{
int count = 0;
for (int i=1; i<=100000; i++)
{
string str = numToString(i);
int j = 0;
while (str[j] > str[j+1])
{
j++;
}
while (j > 0 && str[j] < str[j+1] && j < str.size())
{
j++;
}
if (j == str.size()-1)
{
count++;
}
}
cout<<count<<endl;
return 0;
}
输出:
8193