Beautiful Palindrome Number(回文数)



题目描述

A positive integer x can represent as (a1a2akaka2a1)10 or (a1a2ak−1akak−1a2a1)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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值