mirror of
https://github.com/wczffl-503/OI-Codes.git
synced 2025-07-08 02:13:51 +08:00
Update: Rename folder name to XSMOJ
This commit is contained in:
48
XSMOJ/括弧匹配检验(栈).cpp
Normal file
48
XSMOJ/括弧匹配检验(栈).cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <stack>
|
||||
#include <ctime>
|
||||
#include <cmath>
|
||||
typedef long long l;
|
||||
typedef double d;
|
||||
typedef char c;
|
||||
using namespace std;
|
||||
stack<c> stk;
|
||||
stack<c> stk1;
|
||||
int main(){
|
||||
c a[10000];
|
||||
cin >>a;
|
||||
for(int i=0;i<strlen(a);i++){
|
||||
if(a[i]=='(' || a[i]=='['){
|
||||
stk.push(a[i]);
|
||||
}
|
||||
if(a[i]==')'){
|
||||
if(stk.empty()==1 || stk.top()!='('){
|
||||
cout <<"Wrong";
|
||||
return 0;
|
||||
}
|
||||
else{
|
||||
stk.pop();
|
||||
}
|
||||
}
|
||||
if(a[i]==']'){
|
||||
if(stk.empty()==1 || stk.top()!='['){
|
||||
cout <<"Wrong";
|
||||
return 0;
|
||||
}
|
||||
else{
|
||||
stk.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(stk.empty()==0){
|
||||
cout <<"Wrong";
|
||||
}
|
||||
else{
|
||||
cout <<"OK";
|
||||
}
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user