cswork / OA打开练习工作台

IBMOA #27

Get Final String

估计中等可在线判题

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

Repeatedly delete the contiguous substring AWS from the string until no more deletions are possible, and output the remaining string; output -1 if it is empty.

输入格式

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

输出格式

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

样例 1

输入:

AWAWSSG

输出:

G

样例 2

输入:

AWS

输出:

-1

样例 3

输入:

XYZ

输出:

XYZ

样例说明

The examples give G, -1 and XYZ respectively.