QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#191218 | #7525. Brackets | Days_of_Future_Past# | WA | 1ms | 5644kb | C++14 | 1.1kb | 2023-09-29 20:37:33 | 2023-09-29 20:37:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 4e6+10;
char ip[N];
int n;
int n_plus_back[N];
char ans[N];
int main() {
scanf("%s", ip+1);
n = strlen(ip + 1);
for (int i = n; i > 0; --i) {
if (ip[i] == '+')
n_plus_back[i] = 1 + n_plus_back[i + 1];
}
int it = 0;
for (int i = 1; i <= n;) {
int j = i;
while (ip[j] == '+' && j <= n) ++j;
int var_pos = j;
++j;
while (j <= n && ip[j] == '+') ++j;
int nxt_var = j;
int cnt_pre_incr = (var_pos - i) / 2;
int cnt_post_incr = (nxt_var - var_pos - 1) / 2;
for (int k = 0; k < cnt_post_incr; ++k) {
ans[++it] = '(';
}
for (int k = 0; k < cnt_pre_incr; ++k) {
ans[++it] = '(';
ans[++it] = '+';
ans[++it] = '+';
}
ans[++it] = ip[var_pos];
for (int k = 0; k < cnt_pre_incr; ++k) {
ans[++it] = ')';
}
for (int k = 0; k < cnt_post_incr; ++k) {
ans[++it] = '+';
ans[++it] = '+';
ans[++it] = ')';
}
if (nxt_var <= n) {
ans[++it] = '+';
}
i = j;
}
printf("%s\n", ans + 1);
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5584kb
input:
x+++y
output:
(x++)+y
result:
ok Participant's answer is correct
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 5644kb
input:
q+u+++h+++++o+q++
output:
q+(u++)+((h++)++)+o+(q++)
result:
wrong answer Division by operands in answer is wrong, position: 6