当前位置:网站首页>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");
}
}
边栏推荐
- How is it that desktop icons can't be dragged? Introduction to the solution to the phenomenon that desktop file icons can't be dragged
- PMIX ERROR: ERROR in file gds_ds12_lock_pthread.c
- 基于C语言设计的一个医院叫号系统
- How to do if the right-click attribute of the network neighbor cannot be opened? The solution of the right-click attribute of the network neighbor cannot be opened
- Black one-stop operation and maintenance housekeeper 10 records ro
- C language classic exercises
- The C host is always set separately for IIC. If enough, the next few bits can be set
- 想知道一个C程序是如何进行编译的吗?——带你认识程序的编译
- [cornerstone of high concurrency] multithreading, daemon thread, thread safety, thread synchronization, mutual exclusion
- Yum to see which installation package provides a command
猜你喜欢

Uniapp learning

C语言经典习题之评委打分去掉最高最低求平均分

A hospital call system based on C language

Logback log framework technology in project development

The judges of C language classic exercises score the highest and lowest to get an average score
![Graduation thesis on enterprise production line improvement [Flexsim simulation example]](/img/83/381ef1566d5a863b709f504b46e169.png)
Graduation thesis on enterprise production line improvement [Flexsim simulation example]

What programmer is still being grabbed by the company at the age of 35? Breaking the "middle-aged crisis" of programmers

Design of high frequency small signal resonant amplifier course design Multisim Simulation

The problem of monkeys eating peaches in classic exercises of C language

Post SQL era: edgedb 2.0 Release Notice
随机推荐
PMIX ERROR: ERROR in file gds_ ds12_ lock_ pthread.c
Privacy protection federal learning framework supporting most irregular users
P一个配置文件期间将SDA松集成。支但事实上
Event extraction and documentation (2019)
Billiard simulator based on the integration of GL pipeline and ray tracing technology
Clickpaas, a low code service provider, has completed a strategic merger with BiP technology to jointly build an industrial digital base
Chery arizer 8 products are powerful, and "all excellent" is not for nothing
格式问题处理
Engineer competency model and skill requirements
Label smoothing
力扣146题:LRU缓存
The software cannot be uninstalled. Please wait for the current program to complete the uninstallation or change the solution
What if the computer time is often inaccurate? Set up tutorials to automatically update and proofread computer time
LabVIEW master VI freeze pending
How to solve the engine prompt alias herodb and game engine startup exceptions?
到3mm;提供安全稳定的产品作的执行据发出方iid
Middle aged crisis, workplace dad who dare not leave, how to face life's hesitation
OWA dynamic password SMS authentication scheme solves the problem of outlook email two factor authentication
Several common sorts
Yum to see which installation package provides a command