|
#include<iostream>
#include<stack>
using namespace std;
stack<int> ts;
int main(){
string s;
cin>>s;
for(int i=0;i<s.size();i++){
if(s[i]=='('){
ts.push(s[i]);
}else if(s[i]=='['){
ts.push(s[i]);
}else if(s[i]==']'){
if(!ts.empty()){
char ch = ts.top();
if(ch=='['){
ts.pop();
}else{
cout<<"Wrong";
return 0;
}
}else {
cout<<"Wrong";
return 0;
}
}else if(s[i]==')'){
if(!ts.empty()){
char ch = ts.top();
if(ch=='('){
ts.pop();
}else{
cout<<"Wrong";
return 0;
}
}else {
cout<<"Wrong";
return 0;
}
}
}
if(!ts.empty()){
cout<<"Wrong";
}else{
cout<<"OK" ;
}
return 0;
}
|
|