文章
39
粉丝
0
获赞
80
访问
7.1k
Map定义层级和存储括号对,stack出入匹配括号
#include <iostream>
#include <stack>
#include <map>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
string line;
getline(cin, line); // consume the newline after n
// 定义括号层级:越小越外层
map<char, int> level;
level['{'] = 0;
level['['] = 1;
level['('] = 2;
level['<'] = 3;
// 右括号到左括号的映射
map<char, char> match;
match['}'] = '{';
match[']'] = '[';
match[')'] = '(';
match['>'] = '<';
for (int idx = 0; idx < n; ++idx) {
getline(cin, line);
stack<char> st;
...
登录后发布评论
暂无评论,来抢沙发