题意:给定字符串s,只存在ABC三种字母,相同字母只能变成相同的括号,问最后有没有可能形成合法括号。
思路:第一个括号和最后一个括号肯定是确定的,那就已经确定了两个字母,再分情况讨论最后一个字母的情况,分别括号匹配就可以了。
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fel(i,x,y) for(int i=x;i<=y;i++)
#define fhl(i,x,y) for(int i=x;i>=y;i--)
#define inf 0x3fffffff
#define ll long long
#define pb push_back
#define endl "\n"
#define int long long
string s;
map<char,char>mp;
bool judge(string t){
stack<char>st;
for(auto i:t){
if(i=='('){
st.push('(');
}
else{
if(st.empty()){
return false;
}
else{
st.pop();
}
}
}
return st.empty()? true:false;
}
void slove(){
cin>>s;
int l=s.length();
if(s[l-1]==s[0]){
cout<<"NO"<<endl;
return;
}
mp.clear();