文章
21
粉丝
0
获赞
6
访问
1.5k
stack模拟过程:左括号入栈,出现右括号取顶判断,模拟过程
#include <iostream>
#include <map>
#include <cctype> // for isalpha, tolower
#include <string>
#include<algorithm>
#include<stack>
using namespace std;
int main() {
string s;
cin >> s;
stack<char> st;
bool valid = true;
for (int i = 0; i < s.length(); i++) {
char c = s[i];
if (c == '(' || c == '[' || c == '{' || c == '<') {
st.push(c);
}
else if (c == ')' || c == ']' || c == '}' || c == '>') {
if (st.empty()) {
valid = false;
...
登录后发布评论
暂无评论,来抢沙发