Codeforces Round #360 B

Lovely Palindromes

题意:给一个n,求第n大的长度为偶数的回文数字

思路:只考虑回文的前一半数字,因为前面是高位,肯定优先满足高位,第n大是数字就是n,后半部分由回文自动满足得到,所以其实就是正着输出一遍,倒着再输出一遍

AC代码:

#include "iostream"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include "algorithm"
#include "stdio.h"
#include "math.h"
#pragma comment(linker, "/STACK:102400000,102400000")
#define ll long long
#define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
#define mem(a,x) memset(a,x,sizeof(a))
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define lrt (rt<<1)
#define rrt (rt<<1|1)
using namespace std;
const long long INF = 1e18+1LL;
const int inf = 1e9+1e8;
const int N=1e5+100;
const ll mod=1e9+7;

///BBBB
char s[N];
int main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>s+1;
    int l=strlen(s+1);
    for(int i=1; i<=l; ++i){
        cout<<s[i];
    }
    for(int i=l; i>=1; --i){
        cout<<s[i];
    }
    return 0;
}

 

posted on 2017-07-31 18:52  lazzzy  阅读(97)  评论(0编辑  收藏  举报

导航