文章
34
粉丝
89
获赞
2
访问
19.1k
#include<bits/stdc++.h>
using namespace std;
int GetPriority(char ch){
if(ch == '(' || ch == ')') return 1;
if(ch == '<' || ch == '>') return 2;
if(ch == '[' || ch == ']') return 3;
if(ch == '{' || ch == '}') return 4;
}
bool is_Left(char ch){
if(ch == '<' || ch == '(' || ch == '{' || ch == '['){
return true;
}
return false;
}
stack<char> sta;
int main() {
string para;
bool is_fit = true;
while(cin >> para){
int len = para.size();
for(int i = 0;i < len;i++){
char ch = para[i];
if(is_Left(ch)){
sta.push(ch);
}else{
if(sta.empty()){
is_fit = false;
}else{
int left = GetPriority(sta.top());
int right = GetPriority(ch);
if(left == right){
sta.pop();
...
登录后发布评论
暂无评论,来抢沙发