//这里主要弄清楚实际运算中的括号匹配规律,这样可以减少很多不必要的代码
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int stack[21];
char str[256];
int main()
{
int i,len,top=0;
cin>>str;
len=strlen(str);
for(i=0;i<len;i++)
{
if(str[i]=='(')
stack[++top]=str[i];
else if(str[i]==')')
{if(top!=0&&stack[top]=='(')
top--;
else
{
cout<<"Wrong";//如果top是')'或者'['或者‘]’都不可能最终匹配
return 0;
}
}
else if(str[i]=='[')
stack[++top]=str[i];
else if(str[i]==']')
{if(top!=0&&stack[top]=='[')
top--;
else
{
cout<<"Wrong";//如果top是'('或者')'或者‘]’都不可能最终匹配
return 0;
}
}
}
if(top!=0) cout<<"Wrong";
else cout<<"OK";
return 0;
}