当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

go语言学习笔记-初识Go语言

The first product of Sepp power battery was officially launched

Blockbuster: the domestic IDE is released, developed by Alibaba, and is completely open source!

Broyage · fusion | savoir que le site officiel de chuangyu mobile end est en ligne et commencer le voyage de sécurité numérique!

Explanation of message passing in DGL

9、 Disk management

Talk about the understanding of fault tolerance mechanism and state consistency in Flink framework

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

Ad20 make logo

Web3基金会「Grant计划」赋能开发者,盘点四大成功项目
随机推荐
Data type
双向RNN与堆叠的双向RNN
流程控制、
风控模型启用前的最后一道工序,80%的童鞋在这都踩坑
AD20 制作 Logo
【JS】提取字符串中的分数,汇总后算出平均分,并与每个分数比较,输出
Broyage · fusion | savoir que le site officiel de chuangyu mobile end est en ligne et commencer le voyage de sécurité numérique!
DGL中异构图的一些理解以及异构图卷积HeteroGraphConv的用法
websocket
变量///
关于vray 5.2的使用(自研笔记)(二)
Go语言-1-开发环境配置
Scaffold development foundation
Coneroller执行时候的-26374及-26377错误
数据库中的范式:第一范式,第二范式,第三范式
上拉加载原理
九度 1480:最大上升子序列和(动态规划思想求最值)
SQL Server monitoring statistics blocking script information
Web Security
vite//