A. Palindromic Supersequence

You are given a string A. Find a string B, where B is a palindrome and A is a subsequence of B.

A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequence of "contest".

A palindrome is a string that reads the same forward or backward.

The length of string B should be at most 104. It is guaranteed that there always exists such string.

You do not need to find the shortest answer, the only restriction is that the length of string B should not exceed 104.

Input

First line contains a string A (1 ≤ |A| ≤ 103) consisting of lowercase Latin letters, where |A| is a length of A.

Output

Output single line containing B consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string B should not exceed 104. If there are many possible B, print any of them.

Examples
Input
Copy
aba
Output
aba
Input
Copy
ab
Output
aabaa
Note

In the first example, "aba" is a subsequence of "aba" which is a palindrome.

In the second example, "ab" is a subsequence of "aabaa" which is a palindrome.

题意:将所给字符串形成回文字符串

思路:大水题,由于原字符串长度最大为1e3,要求形成的回文字符串最大为1e4,如果源字符串为回文字符串

的左半部分,最大为2000的长度

#include<bits/stdc++.h>
using namespace std;
int main(){
	string str;
	cin>>str;
	cout<<str;
	reverse(str.begin(),str.end());
	cout<<str<<endl;
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段代码也可以实现在一个区间内寻找回文数并计算它们的和。 其中 `isPalindromic` 函数用于判断一个数是否为回文数,`getInputs` 函数用于获取区间的上边界和下边界,并检查用户的输入是否合法。在主程序中,我们首先调用 `getInputs` 函数获取区间的上边界和下边界,然后通过循环遍历这个区间,找到其中所有回文数,并将它们存储在一个列表中。最后,我们计算这些回文数的总和,并输出结果。 这段代码的工作流程与之前的示例代码基本相同,唯一的区别是在输入区间时,代码将上边界和下边界分别存储在 `upper` 和 `lower` 变量中,并检查它们的大小关系。如果用户输入的上边界比下边界小,则交换它们的值,以确保下边界始终小于或等于上边界。 下面是这段代码的完整实现: ```python def isPalindromic(n): s = str(n) return s == s[::-1] def getInputs(): count = 0 while count < 3: try: upper = int(input("请输入区间的上边界:")) lower = int(input("请输入区间的下边界:")) if upper > lower: upper, lower = lower, upper return upper, lower except: print("输入有误,请重新输入!") count += 1 print("输入错误次数过多,程序退出!") exit() palindromic_list = [] upper, lower = getInputs() for i in range(lower, upper + 1): if isPalindromic(i): palindromic_list.append(i) total = sum(palindromic_list) print("区间[{},{}]中的回文数为:{}".format(lower, upper, palindromic_list)) print("它们的和为:{}".format(total)) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值