当前位置:网站首页>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;
}
边栏推荐
- 风控模型启用前的最后一道工序,80%的童鞋在这都踩坑
- Array
- Go-3-the first go program
- SQL Server monitoring statistics blocking script information
- regular expression
- Nine degrees 1480: maximum ascending subsequence sum (dynamic programming idea for the maximum value)
- Crawler (9) - scrape framework (1) | scrape asynchronous web crawler framework
- 【DNS】“Can‘t resolve host“ as non-root user, but works fine as root
- [observation] with the rise of the "independent station" model of cross-border e-commerce, how to seize the next dividend explosion era?
- 流程控制、
猜你喜欢

DGL中异构图的一些理解以及异构图卷积HeteroGraphConv的用法

关于vray 5.2的使用(自研笔记)

32: Chapter 3: development of pass service: 15: Browser storage media, introduction; (cookie,Session Storage,Local Storage)

微信核酸检测预约小程序系统毕业设计毕设(7)中期检查报告

Go language-1-development environment configuration

Do you really understand the things about "prototype"? [part I]

2022年流动式起重机司机考试题库及模拟考试

小红书自研KV存储架构如何实现万亿量级存储与跨云多活

The first product of Sepp power battery was officially launched

csdn软件测试入门的测试基本流程
随机推荐
C language QQ chat room small project [complete source code]
运算符、、
2022年危险化学品经营单位主要负责人特种作业证考试题库及答案
使用GBase 8c数据库过程中报错:80000502,Cluster:%s is busy,是怎么回事?
Use bat command to launch common browsers with one click
重磅:国产IDE发布,由阿里研发,完全开源!
Pull up loading principle
Taro advanced
SAP ui5 objectpagelayout control usage sharing
Go-3-第一个Go程序
C#实现获取DevExpress中GridView表格进行过滤或排序后的数据
Web Components
Lazy loading scheme of pictures
BOM//
Nine degrees 1480: maximum ascending subsequence sum (dynamic programming idea for the maximum value)
SQL Server monitoring statistics blocking script information
uniapp
[可能没有默认的字体]Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename……
Go language-1-development environment configuration
Go-3-the first go program