比赛 |
板子大赛 |
评测结果 |
AAAAAA |
题目名称 |
多种括号匹配 |
最终得分 |
100 |
用户昵称 |
zqy |
运行时间 |
0.018 s |
代码语言 |
C++ |
内存使用 |
3.41 MiB |
提交时间 |
2025-01-22 09:02:17 |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char s[305],stk[305];
int n,top;
int main(){
freopen("check.in","r",stdin);
freopen("check.out","w",stdout);
scanf("%s",s+1);
n=strlen(s+1);
for(int i=1;i<=n;i++){
if(s[i]=='('||s[i]=='['||s[i]=='{'){
stk[++top]=s[i];
}else{
if(!top){
printf("Wrong\n");return 0;
}
if(s[i]==')'&&stk[top]=='(')top--;
else if(s[i]==']'&&stk[top]=='[')top--;
else if(s[i]=='}'&&stk[top]=='}')top--;
else{
printf("Wrong\n");return 0;
}
}
}
if(!top)printf("OK\n");
else printf("Wrong\n");
return 0;
}