P20962 [GeeksforGeeks] Cd4b48615a30999443b728a72de6cd5addbd0501
提高-
题目描述

IPL 2021 knockouts are over, teams MI, CSK, DC, and RCB are qualified for the semis.
Today is matchday 6 and it is between Delhi Capitals and Royal Challengers Banglore. Glenn Maxwell of RCB playing flawlessly. Rishabh Pant, the new captain of the team who is also a wicket-keeper wants to send a message to the bowler. But, he can't shout message directly as a batsman can hear. So, he decided to encrypt the message by putting ''s in the message. And this is how the bowler decrypts the message. Bowler iterates over the message string from left to right, if he finds a '', he removes it and adds all the letters read so far to the message. He keeps on doing this till he gets rid of all the ''. Given a decrypted message in the form of the string, the task is to find the encrypted message.
Note: If the string can be encrypted in multiple ways, find the encrypted string of smallest length.
Example 1:
Input: s = "ababcababcd"
Output: ab
cd
Explanation: We can encrypt the string
in following way : "ababcababcd" ->
"ababc
d" -> "abcd"
Example 2:
Input: s = "zzzzzzz"
Output: zzz
Explanation: The string can be encrypted
in 2 ways: "zzz" and "zzzz". Out of
the two "z
z
z" is smaller in length.
Your Task:
You don't need to read input or print anything. Complete the function compress() which takes the message string s as input parameter and returns the shortest possible encrypted string.
Constraints:
1 ≤ |s| ≤ 10^{5}

输入格式

见题面

输出格式

见题面

样例输入
s = "ababcababcd"
样例输出
ab*c*d