题解 | 小苯的括号疑问
小苯的括号疑问
https://www.nowcoder.com/practice/db2ad15e614943f2a56a7f419e9b932f
#include <iostream>
#include <string>
using namespace std;
void solve()
{
string s;
cin>>s;
if(s.size()%2!=0) cout<<"-1";
if(s.size()==2) cout<<"()";
if(s.size()%2==0 && s.size()>=4) cout<<"There are multiple solutions";
cout<<endl;
}
int main()
{
int T;
cin>>T;
while(T--) solve();
return 0;
}
// 64 位输出请用 printf("%lld")
只有3种情况
1.括号个数为奇数,不合法,打印出-1
2.括号个数为2,打印出()
3.括号个数为偶数,且>=4,此时一定会有多种情况,打印There are multiple solutions
查看11道真题和解析