比赛 板子大赛 评测结果 AAAAAA
题目名称 多种括号匹配 最终得分 100
用户昵称 AeeE5x 运行时间 0.018 s
代码语言 C++ 内存使用 3.31 MiB
提交时间 2025-01-22 09:16:17
显示代码纯文本
  1. #include<iostream>
  2. #include<stack>
  3. using namespace std;
  4. int f(char x){
  5. if(x=='('||x==')') return 1;
  6. return 2;
  7. }
  8. bool ilg(string s){
  9. stack<int> st;
  10. for(int i=0;i<s.length();i++){
  11. if(s[i]=='('||s[i]=='[') st.push(f(s[i]));
  12. else{
  13. if(st.empty()) return false;
  14. if(st.top()!=f(s[i])) return false;
  15. st.pop();
  16. }
  17. }
  18. return st.empty();
  19. }
  20. int main(){
  21. freopen("check.in","r",stdin);
  22. freopen("check.out","w",stdout);
  23. string s;cin>>s;
  24. if(ilg(s)) cout<<"OK";
  25. else cout<<"Wrong";
  26. return 0;
  27. }