当前位置:网站首页>P1739 expression bracket matching problem solution
P1739 expression bracket matching problem solution
2022-07-24 08:03:00 【bj_ hacker】
P1739 Expression bracket matching problem solution
subject
link
https://www.luogu.com.cn/problem/P1739
Literal description
Title Description
Let's say an expression has letters ( A lowercase letter )、 Operator (+,—,*,/) And left and right little ( round ) Bracket construction , With “@” As the terminator of an expression . Please write a program to check whether the left and right parentheses in the expression match , If the match , Then return to “YES”; Otherwise return to “NO”. The length of the expression is less than 255, The left parenthesis is less than 20 individual .
Input format
a line : expression
Output format
a line :“YES” or “NO”
I/o sample
Input #1 Copy
2*(x+y)/(1-x)@
Output #1 Copy
YES
Input #2 Copy
(25+x)(a(a+b+b)@
Output #2 Copy
NO
explain / Tips
The length of the expression is less than 255, The left parenthesis is less than 20 individual
Code implementation
#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;
}
边栏推荐
- Summary of study notes (I)
- Markdown basic grammar learning
- 多种优化方法打印100~200之间的素数
- Intelligent robot and intelligent system (Professor Zhengzheng of Dalian University of Technology) -- 5. Bionic robot
- Intelligent robots and intelligent systems (Professor Zheng Zheng of Dalian University of Technology) -- 1. robots and mobile robots
- [linear algebra] deeply understand matrix multiplication, symmetric matrix, positive definite matrix
- Collection of sorting topics
- The difference between online learning and offline learning
- [golang from introduction to practice] student achievement management system
- JSON extractor use in JMeter
猜你喜欢

Starting from scratch C language intensive Part 3: Functions

Train-clean-100 dataset

HCIP第七天

Kubernetes:(一)基本概念

NFT是什么?一篇文章搞懂NFT的概念

What is the NFT concept.. Fully understand NFT market, technology and cases

Hcip day 7

hcip第八天笔记

Case practice - panoramic image mosaic: feature matching method

Movie recommendation system
随机推荐
P3916图的遍历 题解
Vidar-Team战队专访:AS WE DO, AS YOU KNOW.
Binary search common questions
P1739表达式括号匹配题解
*Yolo5 learning * data experiment based on yolo5 face combined with attention model se
Anaconda install pytorch
Appium doctor command error pit - resolved
Collection of linked list topics
SVM linear separable linear support vector machine
Error reported by Nacos: error Nacos failed to start, please see d:\nacos\logs\nacos log for more details.
Perceptron and multilayer neural network, back propagation and computational graph
Android kotlin uses a coroutine instead of a callback function (suspendcoroutine usage)
[linear algebra] deeply understand matrix multiplication, symmetric matrix, positive definite matrix
Devops essay
学习-用do…while循环按公式e=1+1/1!+1/2!+1/3!+…+1/n!计算 e 的值(精度为 1e-6)
NFT概念究竟是怎么回事。。全面了解NFT市场、技术和案例
Do you know the use of string?
Markdown basic grammar learning
One click Copy and import of web interface data into postman
Opencv project practice - credit card recognition