欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1326D1.Prefix-Suffix Palindrome (Easy version)
Prefix-Suffix Palindrome (Easy version)
This is the easy version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string , consisting of lowercase English letters. Find the longest string, , which satisfies the following conditions:
- The length of does not exceed the length of .
- is a palindrome.
- There exists two strings and (possibly empty), such that ( "
$+$" represents concatenation), and is prefix of while is suffix of .
Input
The input consists of multiple test cases. The first line contains a single integer (), the number of test cases. The next lines each describe a test case.
Each test case is a non-empty string , consisting of lowercase English letters.
It is guaranteed that the sum of lengths of strings over all test cases does not exceed .
Output
For each test case, print the longest string which satisfies the conditions described above. If there exists multiple possible solutions, print any of them.
Note
In the first test, the string "a" satisfies all conditions.
In the second test, the string "abcdfdcba" satisfies all conditions, because:
- Its length is , which does not exceed the length of the string , which equals .
- It is a palindrome.
- "
abcdfdcba" "abcdfdc" "ba", and "abcdfdc" is a prefix of while "ba" is a suffix of .
It can be proven that there does not exist a longer string which satisfies the conditions.
In the fourth test, the string "c" is correct, because "c" "c" "``" and or can be empty. The other possible solution for this test is "s".
Samples
5
a
abcdfdcecba
abbaxyzyx
codeforces
acbba
a
abcdfdcba
xyzyx
c
abba
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |