题目链接:
https://codeforces.com/contest/1504/problem/C
题意:
待补全:
思路:
待补全:
代码:
#include<bits/stdc++.h>
using namespace std;
const int N = 110;
typedef pair<int, int> PII;
typedef long long LL;
int main()
{
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
string s;
cin >> s;
string a, b;
a.resize(n);
b.resize(n);
int cnt0 = 0, cnt1 = 0;
for(int i = 0; i < n; i++)
{
if(s[i] == '1') cnt1++;
else cnt0++;
}
//如果1的个数和0的个数不为偶数,那么必然失败
if(cnt0 % 2 || cnt1 % 2) cout << "NO" << endl;
//如果第一位和最后一位不为都1,那么必然失败
else if(s[0] == '0' || s[n - 1] == '0') cout << "NO" << endl;
//除此之外,必然成功
else
{
a[0] = b[0] = '(';
a[n - 1] = b[n - 1] = ')';
int idx1 = 2;
int le = 0;
for(int i = 1; i < n - 1; i++)
{
if(s[i] == '1')
{
if(idx1 <= cnt1 / 2)
{
a[i] = b[i] = '(';
}
else
{
a[i] = b[i] = ')';
}
idx1++;
// cout << a[i] << endl;
}
else
{
if(le % 2 == 1)
{
a[i] = ')';
b[i] = '(';
}
else
{
a[i] = '(';
b[i] = ')';
}
le++;
}
}
cout << "YES" << endl;
cout << a << endl;
cout << b << endl;
}
}
return 0;
}