kyEEcccccc @ 2020-10-04 17:46:08
真的是*了dog了,提交四五次UKE,点还不一样,输入输出修改了还不行。
代码:
#include <bits/stdc++.h>
using namespace std;
char str[110];
bool matched[110];
int main(void) {
// scanf("%s", str);
cin >> str;
int n = strlen(str);
for (int i = 0; i < n; ++i) {
char now = str[i];
if (now == '(' || now == '[') {
continue;
}
char need, bad;
if (now == ')') {
need = '(';
bad = '[';
} else {
need = '[';
bad = '(';
}
for (int j = i - 1; j >= 0; --j) {
if (!matched[j] && str[j] == bad) {
break;
}
if (!matched[j] && str[j] == need) {
matched[j] = 1;
matched[i] = 1;
break;
}
}
}
for (int i = 0; i < n; ++i) {
char now = str[i];
if (matched[i]) {
putchar(now);
} else {
if (now == '(' || now == ')') {
// putchar('(');
// putchar(')');
cout << "()";
} else {
// putchar('[');
// putchar(']');
cout << "[]";
}
}
}
// putchar('\n');
cout << endl;
return 0;
}
提交记录:
https://www.luogu.com.cn/record/39255855
https://www.luogu.com.cn/record/39255830
https://www.luogu.com.cn/record/39255786
https://www.luogu.com.cn/record/39255536
https://www.luogu.com.cn/record/39255153
by kyEEcccccc @ 2020-10-04 17:46:36
@kkksc03 @chen_zhe
by Smile_Cindy @ 2020-10-04 17:48:20
@KevinYao 评测机炸了,估计正在修呢吧。