hdu5062——Beautiful Palindrome Number(模拟)

来源:互联网 发布:uc监控cms 编辑:程序博客网 时间:2024/06/06 03:39

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.

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 99999999using 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