Codeforces 1023 C.Bracket Subsequence-STL(vector) (Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Fi)
。。。
代码:
1 //C
2 #include<iostream>
3 #include<cstdio>
4 #include<cstring>
5 #include<algorithm>
6 #include<bitset>
7 #include<cassert>
8 #include<cctype>
9 #include<cmath>
10 #include<cstdlib>
11 #include<ctime>
12 #include<deque>
13 #include<iomanip>
14 #include<list>
15 #include<map>
16 #include<queue>
17 #include<set>
18 #include<stack>
19 #include<vector>
20 using namespace std;
21 typedef long long ll;
22
23 const double PI=acos(-1.0);
24 const double eps=1e-6;
25 const ll mod=1e9+7;
26 const int inf=0x3f3f3f3f;
27 const int maxn=2*1e5+10;
28 const int maxm=100+10;
29 #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
30
31 char a[maxn];
32
33 int main()
34 {
35 ios;
36 int n,k;
37 cin>>n>>k;
38 cin>>a;
39 vector<char> ans;
40 int temp=k/2,sum1=0,sum2=0;
41 for(int i=0;i<n;i++){
42 if(sum1<temp&&a[i]=='('){
43 ans.push_back(a[i]);
44 sum1++;
45 }
46 if(a[i]==')'&&sum2<sum1){
47 ans.push_back(a[i]);
48 sum2++;
49 }
50
51 }
52 for(int i=0;i<k;i++)
53 cout<<ans[i];
54 cout<<endl;
55 }