wordpress手机颜色seo方案怎么做
题目传送门
思路:括号匹配板子
反思:我用了模拟+打标记的方式但是还是wa了
ac代码
- 用了栈维护 当栈里面个数到达1个以上的时候就可以判断栈顶是否匹配然后重复出入栈操作
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+3;
string s;
bool flag[N];
int n;
void solve()
{cin>>n;cin>>s;s=" "+s;stack<char> st;//fc tbfor(int i=1;i<=n;i++){st.push(s[i]);if(st.size()>1){auto t1=st.top();st.pop();auto t2=st.top();st.pop();if((t1=='c'&&t2=='f')||(t1=='b'&&t2=='t')) continue;else{st.push(t2);st.push(t1);}}}cout<<st.size()<<endl;}
int main(){ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);solve();return 0;
}