首页
DreamJudge
院校信息
考研初试
机试真题
讨论区
兑换中心
登录
注册
上岸
以下题解仅供学习参考使用。
抄袭、复制题解,以达到刷AC率/AC数量或其他目的的行为,在N诺是严格禁止的。
N诺非常重视学术诚信。此类行为将会导致您成为作弊者。具体细则请查看N诺社区规则。
Cookie‘s AE86
2024年3月16日 11:47
括号匹配 题解:c++ stack/map实现
P1501
回复 0
|
赞 0
|
浏览 896
#include<bits/stdc++.h> using namespace std; map<char, char> bkmatch = {{')', '('}, {']', '['}}; bool match(string s); int main(){ string s; cin >> s; if(match(s)) c...
huanghu
2024年3月13日 00:06
括号匹配 题解:
P1501
回复 0
|
赞 1
|
浏览 1.1k
#include<stdio.h> #include<iostream> #include<stack> #include<string> using namespace std; int main(){ stack<char> stk; string str; cin>>str; int len = str.length(); for(int i = 0; i<len; i++){ if(!stk.empty()&&...
buluoxu
2024年3月12日 11:33
括号匹配 题解:巧用栈简单解法
P1501
回复 0
|
赞 1
|
浏览 716
#include <iostream> #include <stack> #include <string> using namespace std; int main(){ stack<char> c; string s; cin >> s; for(int i = 0;i < s.size();i++) { if(s[i] == '(' || s[i] == '[' ) { c.push(s[i]); } else if(s[i] == ']') ...
1935569240
2024年3月7日 15:55
括号匹配 题解:来了哦
P1501
回复 0
|
赞 0
|
浏览 762
#include<iostream> #include<algorithm> #include<stack> #include<string> using namespace std; int main() { stack<char> stac; string s; cin >> s; int len = s.size(); &n...
孙某人
2024年2月18日 18:28
括号匹配 题解:
P1501
回复 0
|
赞 2
|
浏览 759
#include<iostream> #include <string.h> using namespace std; int main(){ char a[10005],stack[10005]; for(int i=0;i<10005;i++){ a[i]=0; stack[i]=0; } int num=0,top=-1; gets(a); for(int i=0;i<strlen(a);i++) { if(num>0){ char now=stack[top];//收集现在的栈顶元素...
小王桐学
2024年2月8日 18:07
括号匹配 题解:C栈
P1501
回复 0
|
赞 0
|
浏览 812
#include <stdio.h> #include <string.h> int JudgeMatch(char *s) { char t[500]; int top = -1,i = 0; while(s[i] != '\0') { while(s[i] == '[' || s[i] == '(') t[++top] = s[i++]; if((s[i] == ')' && t[top] == '(') || (s[i] == ']' && t[top] == '[')) ...
青缘
2022年7月31日 17:49
1501 括号匹配 栈经典题
P1501
回复 1
|
赞 10
|
浏览 6.2k
这是数据结构栈的经典题目 思路如下: 判断输入字符串的每一个字符 如果为左括号,则无脑入栈 如果为右括号,则从栈尾取出最近一次入栈的左括号,看是否匹配 若匹配,则继续下一次迭代,且该左括号出栈 若不匹配,直接返回false 判断栈是否为空 若栈为空,两种情况 整个字符串无左括号,即未有元素入栈。这是一个坑。如果直接忽略这种情况,不做检验,输入“}]]”这种字符串也能通过。所以,我们在取栈内元素进行匹配时,首先判断栈是否为空。若为空直接返回fals...
Hegel
2023年3月24日 10:20
括号匹配(仅有[]与())
P1501
回复 0
|
赞 3
|
浏览 3.2k
#include <iostream> #include <stack> #include <string> using namespace std; int main() { string s; cin>>s; stack <char>st; int i; for(i=0;i<s.size();i++){ if(s[i]=='('||s[i]=='[') st.push(s[i]); else{ if(st.empty()) break; if...
零壹
2023年3月22日 12:23
C-栈
P1501
回复 0
|
赞 1
|
浏览 2.5k
定义个字符数组str用来存输入的字符串,再定义一个栈,刚开始的时候栈为空,直接入栈,当栈中的元素num>0时,判断栈顶括号和下一个即将入栈的括号是否匹配,如果匹配,则出栈,不匹配,则继续入栈。当str中的元素全部遍历完以后,判断栈是否为空,如果为空,则匹配成功,否则匹配失败。 #include<stdio.h> #include<string.h> int main(){ char str[100]; char stack[100]; scanf("%s",str); int len=strlen(str); ...
James
2021年1月31日 16:58
简单模拟
P1501
回复 0
|
赞 0
|
浏览 8.7k
#include <iostream> #include <stack> #include <string> using namespace std; stack <char> st; string s; int main(){ cin>>s; for(int i=0;i<s.size();i++){ if(s[i]=='('||s[i...
1
2
3
题目
括号匹配
题解数量
25
发布题解
在线答疑
热门题解
1
括号匹配(C++ string栈) 题解:
2
1501 括号匹配 栈经典题
3
Runtime Error 通过75%
4
括号匹配 题解:简单之中亦有坑
5
括号匹配 题解:stack
6
括号匹配 题解:用数组来模拟栈+知识点总结图示
7
括号匹配 题解:求大佬解惑,显示runtime error,75%数据通过
8
括号匹配 题解:
9
括号匹配(仅有[]与())
10
括号匹配 题解: