zhao__sd @ 2024-07-22 15:07:08
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
cin>>s;
for(int i=0;i<s.size();i++){
if(s[i]=='['&&s[i+1]!=']'||s[i]=='('&&s[i+1]!=')'){
if(s[i]=='['){
cout<<"[]";
}
if(s[i]=='('){
cout<<"()";
}
continue;
}
if(s[i]==']'&&s[i-1]!='['||s[i]==')'&&s[i-1]!='('){
if(s[i]==']'){
cout<<"[]";
}
if(s[i]==')'){
cout<<"()";
}
continue;
}
cout<<s[i];
}
return 0;
}
我感觉我并没有理解题目的意思
by abc1234shi @ 2024-07-22 15:12:57
@zhao_sd2010 你试试这组hack([]),输出也是([])。
by abc1234shi @ 2024-07-22 15:14:30
@zhao_sd2010 他如果括号是匹配的话,他会将原本的输出,而不是分开输出
by _Deer_Peach_ @ 2024-07-22 15:20:19
这题可以用栈做吧
by zhao__sd @ 2024-07-22 15:47:29
@3247535661 How to do it?
by _Deer_Peach_ @ 2024-07-22 15:48:43
可以先用栈判断是否合法