当前位置:网站首页>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;
}
边栏推荐
- 第五届 Polkadot Hackathon 创业大赛全程回顾,获胜项目揭秘!
- 图片懒加载的方案
- 【Vite】1371- 手把手开发 Vite 插件
- Based on shengteng AI Yisa technology, it launched a full target structured solution for video images, reaching the industry-leading level
- Data types ntext and varchar are incompatible in the not equal to operator - 95 small pang
- Go项目实战—参数绑定,类型转换
- Web Security
- Go-2-Vim IDE常用功能
- 使用bat命令一键启动常用浏览器
- 正则表达式
猜你喜欢
微信核酸检测预约小程序系统毕业设计毕设(8)毕业设计论文模板
LSTM applied to MNIST dataset classification (compared with CNN)
【js学习笔记五十四】BFC方式
Go language learning notes - first acquaintance with go language
[vite] 1371 - develop vite plug-ins by hand
[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!
【DNS】“Can‘t resolve host“ as non-root user, but works fine as root
双向RNN与堆叠的双向RNN
DGL中的消息传递相关内容的讲解
随机推荐
小红书自研KV存储架构如何实现万亿量级存储与跨云多活
Web Components
关于 “原型” 的那些事你真的理解了吗?【上篇】
LSTM applied to MNIST dataset classification (compared with CNN)
数据类型 ntext 和 varchar 在not equal to 运算符中不兼容 -九五小庞
App各大应用商店/应用市场网址汇总
Completion report of communication software development and Application
Crawler (9) - scrape framework (1) | scrape asynchronous web crawler framework
正则表达式
Node の MongoDB Driver
小程序框架Taro
函数///
想请教一下,十大券商有哪些?在线开户是安全么?
关于vray 5.2的使用(自研笔记)
The first product of Sepp power battery was officially launched
【js学习笔记五十四】BFC方式
Applet framework taro
In the year of "mutual entanglement" of mobile phone manufacturers, the "machine sea tactics" failed, and the "slow pace" playing method rose
[vite] 1371 - develop vite plug-ins by hand
Go-3-the first go program