当前位置:网站首页>Bracket matching problem (STL)
Bracket matching problem (STL)
2022-07-05 10:52:00 【Yun Qian】
Bracket matching problem (STL)
The implementation of a handwriting stack has been written above , The principle is the same , Now send a use STL A concise way of writing
#include <cstring>
#include <iostream>
#include <stack>
using namespace std;
bool pp(string str,int length){
stack<char> s;
for(int i = 0; i < length; i++){
if(str[i] == '(' || str[i] == '[' || str[i] == '{'){
s.push(str[i]); // If it's left parenthesis Into the stack
}
else{
if(s.empty())
return false;
char topElem;
topElem = s.top();
s.pop();
if(str[i] == ')' && topElem != '(')
return false;
if(str[i] == ']' && topElem != '[')
return false;
if(str[i] == '}' && topElem != '{')
return false;
}
}
return s.empty();// Judge whether it is an empty stack
}
int main(){
string str;
cin >> str;
if(pp(str,str.size()))
cout << " The match is successful " << endl;
else
cout << " Matching failure " << endl;
return 0;
}
边栏推荐
猜你喜欢
Broyage · fusion | savoir que le site officiel de chuangyu mobile end est en ligne et commencer le voyage de sécurité numérique!
A mining of edu certificate station
Go-3-the first go program
2022鹏城杯web
Talk about the understanding of fault tolerance mechanism and state consistency in Flink framework
2022年T电梯修理操作证考试题及答案
[observation] with the rise of the "independent station" model of cross-border e-commerce, how to seize the next dividend explosion era?
Review the whole process of the 5th Polkadot Hackathon entrepreneurship competition, and uncover the secrets of the winning projects!
32:第三章:开发通行证服务:15:浏览器存储介质,简介;(cookie,Session Storage,Local Storage)
2022年危险化学品经营单位主要负责人特种作业证考试题库及答案
随机推荐
SAP ui5 objectpagelayout control usage sharing
Do you really understand the things about "prototype"? [part I]
数组、、、
Taro advanced
vite//
埋点111
Comparative learning in the period of "arms race"
微信核酸检测预约小程序系统毕业设计毕设(7)中期检查报告
Golang应用专题 - channel
Web Security
flex4 和 flex3 combox 下拉框长度的解决办法
Some understandings of heterogeneous graphs in DGL and the usage of heterogeneous graph convolution heterographconv
TSQL–标示列、GUID 、序列
【SWT组件】内容滚动组件 ScrolledComposite
Bidirectional RNN and stacked bidirectional RNN
Go语言-1-开发环境配置
Lazy loading scheme of pictures
MFC宠物商店信息管理系统
关于vray 5.2的使用(自研笔记)
Buried point 111