题意
东东有一个字符串X,该串包含偶数个字符,一半是 S 字符,一半是 T 字符
东东可以对该字符串执行 1010000 次操作:如果存在 ST 是该串的子串,则删除掉最左边的 ST。
即 TSTTSS⇒TTSS、SSSTTT⇒SSTT⇒ST⇒空
Input
(2 ≦ |X| ≦ 200,000)
Output
输出最终串的长度
Example
Input
TSTTSS
Output
4
思想
刚开始只想到了利用while循环暴力解决的方法,然后爆炸了。。。
后来想到可以利用栈先进后出解决此题。
代码
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>