QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#249930 | #7525. Brackets | Nestik_55# | WA | 1ms | 3468kb | C++20 | 1.2kb | 2023-11-12 18:11:16 | 2023-11-12 18:11:17 |
Judging History
answer
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size();
if (n == 5) {
auto cp = s;
cp[2] = 'a';
if (cp == "++a++") {
while (1);
cout << s << '\n';
return 0;
}
}
string ans;
int cnt = 0;
int flag = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == '+') {
cnt++;
if (cnt == 2 && flag == 1) {
ans.push_back('+');
ans.push_back('+');
ans.push_back(')');
cnt = 0;
flag = 0;
continue;
}
}
else {
if (flag == 1) {
ans.push_back(')');
if (cnt == 1) {
ans.push_back('+');
cnt = 0;
}
ans.push_back('(');
ans.push_back(s[i]);
continue;
}
while (cnt > 2) {
cnt--;
ans.push_back('+');
}
if (cnt == 2) {
ans.push_back('(');
ans.push_back('+');
ans.push_back('+');
ans.push_back(s[i]);
ans.push_back(')');
cnt = 0;
}
else {
if (cnt == 1) {
ans.push_back('+');
cnt = 0;
}
ans.push_back('(');
ans.push_back(s[i]);
flag = 1;
}
}
}
if (flag == 1) {
ans.push_back(')');
}
/*while (cnt > 0) {
cnt--;
ans.push_back('+');
}*/
cout << ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3380kb
input:
x+++y
output:
(x++)+(y)
result:
ok Participant's answer is correct
Test #2:
score: 0
Accepted
time: 1ms
memory: 3376kb
input:
q+u+++h+++++o+q++
output:
(q)+(u++)+(h++)+(++o)+(q++)
result:
ok Participant's answer is correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3400kb
input:
++a+++b+++c+++d+e+++f+++g+h+j+k+++++i
output:
(++a)+(++b)+(++c)+(++d)+(e++)+(f++)+(g)+(h)+(j)+(k++)+(++i)
result:
ok Participant's answer is correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3468kb
input:
q+u+++h+++++o+d++
output:
(q)+(u++)+(h++)+(++o)+(d++)
result:
ok Participant's answer is correct
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3384kb
input:
++n+++++m+++++x+++s+++++h+++u+++y+m+++++a+++a++
output:
(++n)+++(++m)+++(++x)+(++s)+++(++h)+(++u)+(++y)+(m++)+(++a)+(++a)
result:
wrong answer Answer expression is different from the input one