CodeForces 688B - Lovely Palindromes(思路)

本文介绍了一种算法,用于输出第n大的偶数长度的回文数。通过构造字符串并将其反转来生成回文数,适用于较大数值的情况。

题意:输出第n(1 <= n <= 10^100000)大的偶数长度的回文数。(最小的为11)

因为长度是偶数,所以前后两半之间是相互对称的,又因为一个数字的大小主要取决于较高位数的大小,所以数字的前一半决定数的大小,从1开始,1,2,3……对称即可得11,22,33……

所以将数正着输出后再倒着输出一遍即可(数非常大,需用字符串存)

 

#include<cstdio>  
#include<cstring>  
#include<cctype>  
#include<cstdlib>  
#include<cmath>  
#include<iostream>  
#include<sstream>  
#include<iterator>  
#include<algorithm>  
#include<string>  
#include<vector>  
#include<set>  
#include<map>  
#include<deque>  
#include<queue>  
#include<stack>  
#include<list>  
typedef long long ll;  
typedef unsigned long long llu;  
const int MAXN = 100 + 10;  
const int MAXT = 1000000 + 10;  
const int INF = 0x7f7f7f7f;  
const double pi = acos(-1.0);  
const double EPS = 1e-6;  
using namespace std;  
  
string s;  
  
int main(){  
    cin >> s;  
    cout << s;  
    reverse(s.begin(), s.end());  
    cout << s << endl;  
    return 0;  
}  

 

转载于:https://www.cnblogs.com/tyty-TianTengtt/p/5996042.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值