cswork / OA打开练习工作台

JPMorgan ChaseOA #17

Eliminate Substring

估计中等可在线判题

考点(AI 标注)单调栈与堆字符串

Repeatedly delete AWS from an uppercase string, joining the two sides of each deletion, until AWS no longer appears; output −1 if the result is empty.

输入格式

One line with a string of uppercase English letters, of length 1..100000.

输出格式

Output the final string; output −1 if it is empty.

样例 1

输入:

AWAWSSG

输出:

G

样例 2

输入:

AWS

输出:

-1

样例 3

输入:

AWSSAWS

输出:

S

样例说明

The outputs of the three public examples are, in order: G; -1; S. These answers have been checked by independent enumeration or direct simulation.