当前位置:网站首页>P1739表达式括号匹配题解
P1739表达式括号匹配题解
2022-07-24 07:56:00 【bj_hacker】
题目
链接
https://www.luogu.com.cn/problem/P1739
字面描述
题目描述
假设一个表达式有英文字母(小写)、运算符(+,—,*,/)和左右小(圆)括号构成,以“@”作为表达式的结束符。请编写一个程序检查表达式中的左右圆括号是否匹配,若匹配,则返回“YES”;否则返回“NO”。表达式长度小于255,左圆括号少于20个。
输入格式
一行:表达式
输出格式
一行:“YES” 或“NO”
输入输出样例
输入 #1复制
2*(x+y)/(1-x)@
输出 #1复制
YES
输入 #2复制
(25+x)(a(a+b+b)@
输出 #2复制
NO
说明/提示
表达式长度小于255,左圆括号少于20个
代码实现
#include<bits/stdc++.h>
using namespace std;
const int maxn=50;
string a;
int top=0,flag=1;
int main(){
cin>>a;
int lena=a.length();
for(int i=0;i<lena;i++){
if(a[i]=='(')top++;
else if(a[i]==')'){
if(top>0)top--;
else {
flag=0;
break;
}
}
}
if(flag){
if(top)cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
else cout<<"NO"<<endl;
return 0;
}
边栏推荐
- Appium use
- Markdown basic grammar learning
- Generate API documents using swagger2markup
- About using the alignment function of VMD
- Telecom Customer Churn Prediction challenge baseline [AI competition]
- 【线性代数】深入理解矩阵乘法、对称矩阵、正定矩阵
- Solve the problem that Anaconda navigator cannot be opened
- Selenium basic knowledge automatic search
- Selenium basic knowledge automatically login Baidu online disk
- SVM linear separable linear support vector machine
猜你喜欢

*Yolo5 learning * data experiment based on yolo5 face combined with attention model se

Amber tutorial A17 learning - concept
![[sklearn] RF cross validation out of bag data parameter learning curve grid search](/img/1f/936e4fe42ed97de2c3caa3f025744d.png)
[sklearn] RF cross validation out of bag data parameter learning curve grid search

Function analysis of e-commerce website development and construction

Full revolutionary Siamese networks for object tracking translation

Decision tree - ID3, C4.5, cart

【sklearn】PCA

简易网闸-内网服务器安全获取外网数据

Arduino在不同主频下稳定支持的TTL串口速率

hcip第十三天笔记
随机推荐
Super simple countdown code writing
Opencv project - credit card recognition (learning record)
MS SQL Server 2019 learning
避坑,职场远离PUA,PUA常见的套路与话术你得了解一下!
*Code understanding *numpy basic (plus code) that must be understood
Selenium use
Project practice - document scanning OCR recognition
Generative model and discriminant model
Common DOS commands
About how to set colored fonts on the terminal
(dkby) DFL learning notes
Jersey2.25.1 integration freemaker
Vertex buffer and shader (the cherno + leranopongl) notes
OpenGL camera and periodic review
About using the alignment function of VMD
Example of dictionary
Jetson AgX Orin source change
13. Unity2d horizontal version of two-way platform that can move up, down, left and right (two-way walking + movable + independent judgment) + random platform generation
Hcip 13th day notes
【线性代数】深入理解矩阵乘法、对称矩阵、正定矩阵