2020 is a special integer, it’s formed of two same integers (20 and 20).
We call a number is a good number, if and only if it can be formed of two same integers(without leading zero).
For example: 2020 11, 19991999 are good numbers, but 303, 1122, 1221 are not.
Now you need to count the number of good numbers in [1,N][1,N][1,N]


题意
给出一个 <=1e18 的n 求从1到n中有多少个数是由两个相同的数构成的。
思路
输入字符串写出打表程序,发现
奇数时答案为s.size()/2 个9
偶数时把字符串分成两半,如果后面的数大于等于前面的,就输出前面的数,否则把字符串转换为数减一后输出。
代码
打表代码
#include <bits/stdc++.h>
using namespace std;
bool ok(string s)
{
int len = s.size();
if(len & 1) return false;
string now1 = "" , now2 = "";
for

博客围绕计算[1,N]中由两个相同整数构成(无前导零)的好数数量展开。先明确好数定义,如2020、19991999等。接着给出解题思路,奇数和偶数情况处理不同。最后展示了打表代码和AC代码。
最低0.47元/天 解锁文章
4492





