ACWing 4207. 最长合法括号子序列

复制代码
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 int main()
 5 {
 6   string s;
 7   cin>>s;
 8   int ans=0,cnt=0;
 9   for(auto &p:s)
10   {
11     if(p=='(')cnt++;
12     else
13     {
14       if(cnt)
15       {
16         cnt--;
17         ans+=2;
18       }
19     }
20   }
21   cout<<ans<<endl;
22   return 0;
23 }
复制代码

 

posted @   matt-11  阅读(39)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示