当前位置:网站首页>C. Recover an RBS (parenthesis sequence, thinking)
C. Recover an RBS (parenthesis sequence, thinking)
2022-07-24 04:44:00 【to cling】
Educational Codeforces Round 132 (Rated for Div. 2)
Problem
Give a sequence of parentheses . Now replace a few of these characters with '?'. ask : Is there only one legal solution , So that the sequence can be translated into the correct arithmetic expression .
Input guarantees that at least one legal scheme exists .
Solution
cnt: Indicates the number of left parentheses
num: Indicates the currently undetermined number of question marks
Traverse from left to right , See code for details
Code
int main()
{
int T; cin >> T;
while (T--)
{
string s; cin >> s;
int len = s.size();
int cnt = 0, num = 0;
s[0] = '(';
for (int i = 0; i < len; i++)
{
if (s[i] == '(') cnt++;
else if (s[i] == ')')
{
cnt--;
if (cnt < 0) cnt++, num--;// The previous undetermined question mark needs to be determined as '('
}
else num++;
if (cnt == 0 && num == 1) cnt = 1, num = 0;// Similar to the parenthesis sequence, the first one is '?', therefore '?' It should be determined as '('
}
cout << (cnt == num ? "YES\n" : "NO\n");
}
}
边栏推荐
- What if IPv4 has no internet access? Solutions to IPv4 without internet access rights (detailed explanation of pictures and texts)
- 在一线城市上班的程序员,家庭一般是怎样的?
- C language: bubble sorting
- 格式问题处理
- How can I open and view the bin file? Diagram of reading method of bin file backed up by router
- Esp32 tutorial (I): vscode+platform and vscade+esp-idf
- 一次线上事故,我顿悟了异步的精髓
- Is it true to pay attention to official account and receive Xiaomi mobile power for free? Wechat circle of friends sends Xiaomi mobile power
- IP second experiment mGRE OSPF
- Merge sort
猜你喜欢

Array force buckle (continuously updated)

C语言经典习题之编写一个程序,找出1000以内所有的完数。

greatest common divisor

激活函数和最常用的10个激活函数

Journey of little black leetcode: 341. Flattening nested list iterator

打印1000年到2000年之间的闰年
[hope to answer] the data cannot be synchronized correctly

Nautilus 3.19.2为Gnome增添动力

Nautilus 3.19.2 adds momentum to Gnome

Application scenarios and schemes of common mechanical equipment safety virtual simulation system
随机推荐
Excel cell formula - realize Ackerman function calculation
C语言基础学习笔记
Logback log framework technology in project development
Chery arizer 8 products are powerful, and "all excellent" is not for nothing
The judges of C language classic exercises score the highest and lowest to get an average score
LabVIEW master VI freeze pending
Common cross domain problems
Application scenarios and schemes of common mechanical equipment safety virtual simulation system
HMS core discovery Episode 16 live broadcast preview | play AI's new "sound" state with tiger pier
Add.Eslinctrc.js under SRC for the general format of the project
C language classic exercises to write a program to find all the perfects within 1000.
Event extraction and documentation (2019)
What if the notepad file is too large to open? Introduction to the solution to the phenomenon that txt files are too large to be opened
Journey of little black leetcode: 590. Post order traversal of n-ary tree
激活函数和最常用的10个激活函数
黑色的的一站式运维管家 10条记录RO
How to register and apply for free for Apple Developer account in order to enjoy the upgrade experience at the first time
Format problem handling
Clickpaas, a low code service provider, has completed a strategic merger with BiP technology to jointly build an industrial digital base
Pony activation tool appears cannot open file k:\oemsf solution