当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
【Vite】1371- 手把手开发 Vite 插件
5g NR system architecture
Implement the rising edge in C #, and simulate the PLC environment to verify the difference between if statement using the rising edge and not using the rising edge
磨礪·聚變|知道創宇移動端官網煥新上線,開啟數字安全之旅!
AD20 制作 Logo
ModuleNotFoundError: No module named ‘scrapy‘ 终极解决方式
Go-3-第一个Go程序
2022年T电梯修理操作证考试题及答案
磨砺·聚变|知道创宇移动端官网焕新上线,开启数字安全之旅!
2022年流动式起重机司机考试题库及模拟考试
随机推荐
Implementation of wechat applet bottom loading and pull-down refresh
Function///
Comparative learning in the period of "arms race"
go语言学习笔记-初识Go语言
Taro进阶
Coneroller执行时候的-26374及-26377错误
Blockbuster: the domestic IDE is released, developed by Alibaba, and is completely open source!
数据类型、
Web Security
LSTM应用于MNIST数据集分类(与CNN做对比)
Web3基金会「Grant计划」赋能开发者,盘点四大成功项目
使用GBase 8c数据库过程中报错:80000502,Cluster:%s is busy,是怎么回事?
Scaffold development foundation
上拉加载原理
Operators
[可能没有默认的字体]Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename……
32:第三章:开发通行证服务:15:浏览器存储介质,简介;(cookie,Session Storage,Local Storage)
NAS and San
【tcp】服务器上tcp连接状态json形式输出
Go-3-第一个Go程序