CodeForces - 1023C
原创
©著作权归作者所有:来自51CTO博客作者Nirvana柒的原创作品,请联系作者获取转载授权,否则将追究法律责任
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;
}