hdu5062——Beautiful Palindrome Number(模拟)

Problem Description
A positive integer x can represent as (a1a2akaka2a1)10 or (a1a2ak1akak1a2a1)10 of a 10-based notational system, we always call x is a Palindrome Number. If it satisfies 0<a1<a2<<ak9 , we call x is a Beautiful Palindrome Number.
Now, we want to know how many Beautiful Palindrome Numbers are between 1 and 10N .

Input
The first line in the input file is an integer T(1T7) , indicating the number of test cases. Then T lines follow, each line represent an integer N(0N6) .

Output
For each test case, output the number of Beautiful Palindrome Number.

Sample Input
2
1
6

Sample Output
9
258

输入只有其中情况,可以事先算出来,直接把答案存到数组里

#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cstdio>
#include <set>
#include <math.h>
#include <algorithm>
#include <queue>
#include <iomanip>
#define INF 0x3f3f3f3f
#define MAXN 6005
#define Mod 99999999
using namespace std;
int main()
{
    /*for(int n=0; n<=6; ++n)
    {
        int len=pow(10,n),ans=0;
        for(int i=1; i<=len; ++i)
        {
            if(i>=1&&i<=9)
                ans++;
            else if(i>=10&&i<=99)
            {
                int a=i/10,b=i%10;
                if(a==b)
                {
                    ans++;
                    //cout<<i<<endl;
                }
            }
            else if(i>=100&&i<=999)
            {
                int a=i/100,b=(i/10)%10,c=i%10;
                if(a<b&&a==c)
                {
                    ans++;
                    //cout<<i<<endl;
                }
            }
            else if(i>=1000&&i<=9999)
            {
                int k1=i/1000,k2=(i/100)%10,k3=(i/10)%10,k4=i%10;
                if(k1==k4&&k2==k3&&k1<k2)
                {
                    ans++;
                    //cout<<i<<endl;
                }
            }
            else if(i>=10000&&i<=99999)
            {
                int k1=i/10000,k2=(i/1000)%10,k3=(i/100)%10,k4=(i/10)%10,k5=i%10;
                if(k1==k5&&k2==k4&&k1<k2&&k2<k3)
                {
                    ans++;
                    cout<<i<<endl;
                }
            }
            else if(i>=100000&&i<=999999)
            {
                int k1=i/100000,k2=(i/10000)%10,k3=(i/1000)%10,k4=(i/100)%10,k5=(i/10)%10,k6=i%10;
                if(k1==k6&&k2==k5&&k3==k4&&k1<k2&&k3<k4&&k2<k3)
                {
                    ans++;
                    //cout<<i<<endl;
                }
            }

        }
        cout<<n<<" "<<len<<" "<<ans<<endl;
    }
    return 0;*/
    int a[]={1,9,18,54,90,174,258};
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        cout<<a[n]<<endl;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值