FTHX @ 2024-05-22 21:39:36
测评记录
#include <bits/stdc++.h>
using namespace std;
string a;
bool b[1000];
int main() {
for (int i = 0; i <= 105; i++) {
b[i] = true;
}
cin >> a;
for (int i = 0; i < a.length(); i++) {
if (a[i] == ')') {
for (int j = i - 1; j >= 0; j--) {
if (a[j] == '(' && b[j] == true) {
b[i] = b[j] = false;
break;
} else if (a[j] == '[' && b[j] == true) {
break;
}
}
}
else if (a[i] == ']') {
for (int j = i - 1; j >= 0; j--) {
if (a[j] == '[' && b[j] == true) {
b[i] = b[j] = false;
break;
} else if (a[j] == '[' && b[j] == true) {
break;
}
}
}
}
for (int i = 0; i < a.length(); i++) {
if (b[i] == true) {
if (a[i] == '(' || a[i] == ')') {
cout << "()";
} else
cout << "[]";
} else {
cout << a[i];
}
}
return 0;
}
by pink12345 @ 2024-06-20 15:42:41
else if (a[i] == ']')
{
for (int j = i - 1; j >= 0; j--)
{
if (a[j] == '[' && b[j] == true)
{
b[i] = b[j] = false;
break;
}
else if (a[j] == '[' && b[j] == true)
break;
}
}
else if里面应该是'('吧