题目描述
A positive integer x can represent as (a1a2…akak…a2a1)10 or (a1a2…ak−1akak−1…a2a1)10 of a 10-based notational system, we always call x is a Palindrome Number. If it satisfies 0<a1<a2<…<ak≤9, we call x is a Beautiful Palindrome Number.
Now, we want to know how many Beautiful Palindrome Numbers are between 1 and 10^n
10N
输入
The first line in the input file is an integer T(1≤T≤7), indicating the number of test cases.
Then T lines follow, each line represent an integer N(0≤N≤6).
输出
For each test case, output the number of Beautiful Palindrome Number.
样例输入
2
1
6
样例输出
9
258
回文数,做题时翻译没有正确理解这道题,后来发现 打表也能过。。。。。。。。
代码如下
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mem(a) memset(a, 0, sizeof(a))
#define eps 1e-5
#define INF 0x1f1f1f1f
#define M 100005
using namespace std;
int Case = 1;
int t, n, m;
int a[10];
int f(int n) {
int cnt = 0;
while(n) {
a[cnt++] = n % 10;
n /= 10;
}
int x = 0, y = cnt-1;
while(x < y) {
if(a[x] != a[y]) {
return 0;
}
x++; y--;
}
for(int i = 1; i <= (cnt-1)/2; i++) {
if(a[i] <= a[i-1]) {
return 0;
}
}
return 1;
}
int main()
{
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
m = 1;
for(int i = 0; i < n; i++) {
m *= 10;
}
int sum = 0;
for(int i = 1; i <= m; i++) {
if(f(i)) {
sum++;
}
}
printf("%d\n", sum);
}
return 0;
}