QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#249862#7525. BracketsNestik_55#WA 1ms3468kbC++201.1kb2023-11-12 17:02:412023-11-12 17:02:42

Judging History

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

  • [2023-11-12 17:02:42]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3468kb
  • [2023-11-12 17:02:41]
  • 提交

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(')');
	}

	cout << ans;

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3460kb

input:

x+++y

output:

(x++)+(y)

result:

ok Participant's answer is correct

Test #2:

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

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: 1ms
memory: 3468kb

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

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: 1ms
memory: 3468kb

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