CodeForces - 1023C_ios


CodeForces - 1023C_ios_02

AC代码:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;

char a[200010], b[200010];
int main()
{
int n, m;
scanf("%d%d", &n, &m);
scanf("%s", a);
memset(b, 0, sizeof(b));
int j = 0, x = 0;
for (int i = 0; i < strlen(a); i++) { //记录"("数量
if (a[i] == '(') {
b[j++] = '(';
x++;
}
if (a[i] == ')') {
b[j++] = ')';
}
if (x == m / 2)
break;
}
for (int i = j; i < m; i++) //补全")"
b[i] = ')';
cout << b;
return 0;
}