QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#657998 | #7894. Many Many Heads | chie4 | WA | 0ms | 3544kb | C++14 | 1.3kb | 2024-10-19 15:57:05 | 2024-10-19 15:57:08 |
Judging History
answer
#include <algorithm>
#include <iostream>
#include <string>
int main() {
int t, length, half;
bool ans;
std::string s, tmp_s, reversed_s;
std::cin >> t;
for (int i = 0; i < t; i++) {
std::cin >> s;
length = s.size();
half = length >> 1;
tmp_s = s;
std::replace(tmp_s.begin(), tmp_s.end(), '(', 'r');
std::replace(tmp_s.begin(), tmp_s.end(), ')', 'r');
std::replace(tmp_s.begin(), tmp_s.end(), '[', 's');
std::replace(tmp_s.begin(), tmp_s.end(), ']', 's');
if (length % 2 == 1 || length <= 2) {
std::cout << "Yes" << std::endl;
continue;
}
reversed_s = tmp_s.substr(half, length);
std::reverse(reversed_s.begin(), reversed_s.end());
ans = tmp_s.substr(0, half) == reversed_s;
if (ans) {
ans = tmp_s.substr(0, half).find("ss") != std::string::npos ||
tmp_s.substr(0, half).find("rr") != std::string::npos;
} else {
ans = tmp_s.substr(0, half).find("ssss") != std::string::npos ||
tmp_s.substr(0, half).find("rrrr") != std::string::npos;
}
if (ans) {
std::cout << "No" << std::endl;
} else {
std::cout << "Yes" << std::endl;
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3508kb
input:
6 )) ((() [()] ()[()]() ([()]) ([])([])
output:
Yes No Yes No Yes No
result:
ok 6 token(s): yes count is 3, no count is 3
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3544kb
input:
2 (([([[([ ]]))])]])]
output:
Yes Yes
result:
wrong answer expected NO, found YES [2nd token]