#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
#define max_size 100000
class stack{
public:
int top;
char data[max_size];
int index[max_size];
stack(){
top = 0;
}
void Pushstack(char v,int pos){
if(top<max_size){
data[top]=v;
index[top]=pos;
top++;
}
}
bool Popstack(char& v,int& pos){
if(top==0) return false;
top--;
v=data[top];
pos=index[top];
return true;
}
bool isempty(){
return top==0;
}
};
int main(){
string s;
while(getline(cin,s)){
stack S;
int cnt = 0;
bool ifmatch[max_size] = {false};
for(int i=0;s.size();i++){
char c = s[i];
if(c=='('||c=='{'||c=='['){
S.Pushstack(c,i);
}else if(c==')'||c==']'||c=='}'){
char x;
int n;
if(S.Popstack(x,n)){
bool m = false;
if(x=='('&&c==')'){
cnt++;
m = true;
}else if(x=='['&&c==']'){
cnt++;
m = true;
}else if(x=='{'&&c=='}'){
cnt++;
m = true;
}
if(m){
ifmatch[i] = true;
ifmatch[n] = true;
}else{
ifmatch[i] = false;
}
}else{
ifmatch[i] = false;
}
}
}
while(!S.isempty()){
char x;
int n;
S.Popstack(x,n);
ifmatch[n] = false;
}
cout<<cnt<<endl;
bool unmatch = false;
for(int i=0;s.size();i++){
if(!ifmatch[i]){
cout<<s[i];
unmatch = true;
}
}
if(!unmatch){
cout<<" ";
}
cout<<endl;
}
return 0;
}
学校平台一直显示运行错误63%,有大佬帮忙看看指出问题吗。