当前位置:网站首页>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;
}
边栏推荐
- [sklearn] data preprocessing
- Intelligent robots and intelligent systems (Professor Zhengzheng of Dalian University of Technology) -- 4. Autonomous robots
- About using the alignment function of VMD
- Jersey2.25.1 integration freemaker
- mysql update 使用case when根据某一字段的值,更新另一字段的值
- hcip第八天笔记
- *Yolo5 learning * data experiment based on yolo5 face combined with attention model CBAM
- NFT概念究竟是怎么回事。。全面了解NFT市场、技术和案例
- Qt|字符串生成二维码功能
- Learning dynamic Siamese network for visual object tracking full text translation
猜你喜欢

Hcip day 8 notes

When does MySQL use table locks and row locks?

Image feature Harris corner detection

App performance test case

【sklearn】PCA

Opencv project - credit card recognition (learning record)

33-SparkSql的介绍、DataFrame和DataSet

Case practice - panoramic image mosaic: feature matching method

NFT概念究竟是怎么回事。。全面了解NFT市场、技术和案例

Train-clean-100 dataset
随机推荐
Example of dictionary
One click Copy and import of web interface data into postman
Learning to track at 100 FPS with deep progression networks
Anaconda install pytorch
MySQL --- 子查询 - 标量子查询
MySQL 啥时候用表锁,啥时候用行锁?
Jetson AgX Orin source change
Detailed notes on pytoch building neural network
Kubernetes:(一)基本概念
简易网闸-内网服务器安全获取外网数据
Facing Tencent (actual combat) - Test Development - detailed explanation of interns (face experience)
Super simple countdown code writing
Hcip day 8 notes
加密熊市:有人大举扩张 有人裁员收缩
The solution of unable to import custom library in pycharm
Thesis reading: geotransformer
Error when using PIP: pip is configured with locations that requires tls/ssl
Debug No4 use renderdoc to troubleshoot bugs
Natural language processing Jieba
Simple Gateway - intranet server safely obtains external network data