QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#249930#7525. BracketsNestik_55#WA 1ms3468kbC++201.2kb2023-11-12 18:11:162023-11-12 18:11:17

Judging History

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

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

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;
}

詳細信息

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