欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1654B.Prefix Removals
Prefix Removals
You are given a string consisting of lowercase letters of the English alphabet. You must perform the following algorithm on :
- Let be the length of the longest prefix of which occurs somewhere else in as a contiguous substring (the other occurrence may also intersect the prefix). If , break. Otherwise, remove the first characters of , and repeat.
A prefix is a string consisting of several first letters of a given string, without any reorders. An empty prefix is also a valid prefix. For example, the string "abcd" has 5 prefixes: empty string, "a", "ab", "abc" and "abcd".
For instance, if we perform the algorithm on "abcabdc",
- Initially, "
ab" is the longest prefix that also appears somewhere else as a substring in , so "cabdc" after operation. - Then, "
c" is the longest prefix that also appears somewhere else as a substring in , so "abdc" after operations. - Now (because there are no non-empty prefixes of "
abdc" that also appear somewhere else as a substring in ), so the algorithm terminates.
Find the final state of the string after performing the algorithm.
Input
The first line contains a single integer () — the number of test cases.
This is followed by lines, each containing a description of one test case. Each line contains a string . The given strings consist only of lowercase letters of the English alphabet and have lengths between and inclusive.
It is guaranteed that the sum of the lengths of over all test cases does not exceed .
Output
For each test case, print a single line containing the string after executing the algorithm. It can be shown that such string is non-empty.
Note
The first test case is explained in the statement.
In the second test case, no operations can be performed on .
In the third test case,
- Initially, "
bbbbbbbbbb". - After operation, "
b".
In the fourth test case,
- Initially, "
codeforces". - After operation, "
odeforces". - After operations, "
deforces".
Samples
6
abcabdc
a
bbbbbbbbbb
codeforces
cffcfccffccfcffcfccfcffccffcfccf
zyzyzwxxyyxxyyzzyzzxxwzxwywxwzxxyzzw
abdc
a
b
deforces
cf
xyzzw
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |