提交时间:2023-08-22 21:18:03
运行 ID: 99487
#include <iostream> #include <cstring> using namespace std; void _init_(char arr[],int &top){ arr = {}; top = 0; } void _push_(int &top,char arr[],char value,int maxhigh){ if(top < maxhigh){ top++; arr[top] = value; } } char _pop_(int &top,char arr[]){ if(top > 0){ top--; return arr[top+1]; } return -1; } bool _notempty_(int top){ return top; } int main(){ char arr[101],s[100]; int top; _init_(arr,top); cin.getline(s,100); for(int i=0;i<strlen(s);i++){ if(s[i] == '('){ _push_(top,arr,')',100); } else if(s[i] == '['){ _push_(top,arr,']',100); } else if(s[i] == '{'){ _push_(top,arr,'}',100); } else if(_notempty_(top) && _pop_(top,arr)==s[i]){ continue; } else{ cout << "No"; return 0; } } if(_notempty_(top)){ cout << "No"; return 0; } cout << "Yes"; return 0; }