首页
DreamJudge
院校信息
考研初试
考研复试
保研专区
讨论区
兑换中心
登录
注册
上岸
以下题解仅供学习参考使用。
抄袭、复制题解,以达到刷AC率/AC数量或其他目的的行为,在N诺是严格禁止的。
N诺非常重视学术诚信。此类行为将会导致您成为作弊者。具体细则请查看N诺社区规则。
奶龙大王
2026年1月29日 15:39
括号匹配 题解:
P1501
回复 0
|
赞 1
|
浏览 186
stack模拟过程:左括号入栈,出现右括号取顶判断,模拟过程 #include <iostream> #include <map> #include <cctype> // for isalpha, tolower #include <string> #include<algorithm> #include<stack> using namespace std; int main() { string ...
mlx
2026年1月26日 20:39
括号匹配 题解:
P1501
回复 0
|
赞 1
|
浏览 176
#include<iostream> #include<stack> using namespace std; string str; stack<char> st; bool check() { for(int i=0;i<str.size();i++) { if(str[i]=='('||str[i]=='[') st.push(str[i]); else { if(st.empty()) return false; if(str[i]==']'&&a...
曾不会
2026年1月25日 14:56
括号匹配 题解:
P1501
回复 0
|
赞 0
|
浏览 103
栈匹配 #include<stdio.h> #include<stack> #include<string.h> using namespace std; int main() { char s[100]; scanf("%s",s); int l=strlen(s); // printf("%s\n",s); &...
leo110
2025年5月17日 16:11
括号匹配 题解:
P1501
回复 0
|
赞 1
|
浏览 996
//1067题的代码稍微改一点就行。主要两点不同:①只有两个类型的括号②括号没有优先级 //解题思路:map映射字符为整数,结合数据结构的stack进行括号匹配。 #include<iostream> #include<map> #include<stack> using namespace std; map<char,int> Bracket={{'[',-2},{'(',-1},{')',1},{']',2}}; bool match(co...
阿灿
2025年3月22日 22:45
括号匹配 题解:stack
P1501
回复 0
|
赞 10
|
浏览 1.0k
#include<bits/stdc++.h> using namespace std; int main(){ string str; cin>>str; int n=str.length(); stack<char>st; for(int i=0;i<n;i++){ if(!st.empty()){ char now = st.top(); if(str[i]==')'&&now=='('||now=='['&&str[i]==']'){ st.pop...
wuhududu
2025年3月21日 19:18
括号匹配 题解:
P1501
回复 0
|
赞 4
|
浏览 925
//一定要注意先输入 ')' 或者 ']' 的情况,此时正好栈为空,这个时候检查栈顶元素是不是 '(' 就会出现错误,这是由于栈空时检查栈顶元素是非法的,故在初始化栈的时候就先push一个不会影响括号匹配的元素,保证先输入 ')'不会出现非法的情况; #include<bits/stdc++.h> using namespace std; char s[10000]; int main(){ gets(s); ...
shiv15832
2025年3月16日 15:45
括号匹配 题解:简单之中亦有坑
P1501
回复 0
|
赞 15
|
浏览 1.4k
基本思路:如果是左括号,入栈。如果是右括号,与栈顶匹配,成功栈顶出栈,失败怎么办?如果把匹配过程单独写成一个函数Judge,那就可以直接return flase;如果匹配过程写在main函数里,那就有些麻烦,自己写一写就知道需要引入一些bool变量作为标记,而且可能面临着输出多个NO的情况,大家做题的时候,一条路走着走着越来越麻烦,不如回头在看一看有没有更好的路子。 这道题最重要的一点:如果是右括号,不能仅仅与栈顶匹配,必须要先判定栈是否为空!eg:输入】】【,不加判空就会导致本轮循环空过导致卡75%!不过这一点也是基于代码的不同因人而异,所以我说本题简单中亦有坑,每个人的思路不一...
西电机试专家
2025年2月16日 12:04
括号匹配 题解:用数组来模拟栈+知识点总结图示
P1501
回复 0
|
赞 5
|
浏览 1.1k
#include<bits/stdc++.h> using namespace std; int main(){ string str;//初始字符串 cin>>str; char s[1000];//s为结果处理栈 char a; int top=-1,flag=0;//0说明YES &...
15240928957
2024年3月20日 21:26
Runtime Error 通过75%
P1501
回复 3
|
赞 9
|
浏览 1.4k
#include <iostream> #include <stack> #include <cstring> using namespace std; int main() { stack<int> st; char s[10005]; cin >> s; for (int i = 0; i < strlen(s); i++) &n...
Candour
2024年5月6日 23:30
括号匹配(C++ string栈) 题解:
P1501
回复 0
|
赞 14
|
浏览 1.4k
#include <bits/stdc++.h> using namespace std; string str; int main() { cin >> str; string stk1, stk2; for(int i = 0; i < str.size(); i ++) { if(str[i] == '(') stk1.push_back(')'); else if(str[i] == '[') stk1.push_back(']'); else if(str[i] == ')') stk2....
1
2
3
4
题目
括号匹配
题解数量
38
发布题解
在线答疑
热门题解
1
括号匹配 题解:简单之中亦有坑
2
括号匹配(C++ string栈) 题解:
3
1501 括号匹配 栈经典题
4
括号匹配 题解:stack
5
括号匹配 题解:c++
6
Runtime Error 通过75%
7
括号匹配 题解:75通过率原因
8
括号匹配 题解:用数组来模拟栈+知识点总结图示
9
括号匹配 题解:求大佬解惑,显示runtime error,75%数据通过
10
括号匹配 题解: