QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#249931#7525. BracketsNestik_55#WA 0ms3792kbC++201.1kb2023-11-12 18:12:082023-11-12 18:12:08

Judging History

你现在查看的是最新测评结果

  • [2023-11-12 18:12:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3792kb
  • [2023-11-12 18:12:08]
  • 提交

answer

#include <iostream>
#include <string>

using namespace std;

int main() {
	string s;
	cin >> s;
	int n = s.size();

	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: 0ms
memory: 3460kb

input:

x+++y

output:

(x++)+(y)

result:

ok Participant's answer is correct

Test #2:

score: 0
Accepted
time: 0ms
memory: 3792kb

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: 3528kb

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: 3760kb

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: 3604kb

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 Division by operands in answer is wrong, position: 4