题目
要改变多少个 , {,} ,,才能使序列合法,合法如下
All of these strings are stable: {}, {}{}, and {
{}{}}; But none of these: }{, {
{}{, nor {}{.
思路
一个字符串,去掉合法的对数,对不合法的进行处理即可
不合法有2种情况:
- 只有{或}。那么➗2即可~
- }}}{ { {交替出现:{ {}}}}这种情况为中间过程。{}总数必须为偶数。当为奇数时,如}}}}}{ { {,需要n/2+1次,当}}}{ { {时,需要n/2次
代码
#include <iostream>
#include <stack>
#include <