![](https://images2018.cnblogs.com/blog/1402646/201807/1402646-20180716223719568-807175292.png)
![](https://images2018.cnblogs.com/blog/1402646/201807/1402646-20180716223732122-1428962046.png)
长度为k的回文串个数有9*10^(k-1)
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = 10010, INF = 0x7fffffff;
int num[maxn], a[maxn];
void init()
{
num[1] = num[2] = 9;
for(int i=3; i<20; i+=2)
num[i] = num[i+1] = num[i-1] * 10;
}
int main()
{
init();
LL n;
while(cin>> n && n)
{
mem(a, 0);
int len = 1;
while(n - num[len] > 0)
{
n -= num[len];
len++;
}
n--;
for(int i=len/2+1; i<=len; i++)
{
a[i] = n%10;
n /= 10;
}
a[len]++;
for(int i=1; i<=len/2; i++)
a[i] = a[len-i+1];
for(int i=1; i<=len; i++)
printf("%d", a[i]);
printf("
");
}
return 0;
}
自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。