QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#788337 | #9565. Birthday Gift | Hans | WA | 1ms | 3804kb | C++23 | 892b | 2024-11-27 16:35:43 | 2024-11-27 16:35:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void solve() {
string str; cin >> str;
str.push_back('b');
vector<int> v;
stack<int> s;
char cur = str[0];
bool seq_is_odd = false;
for (int i = 0; i < str.size(); i++) {
if (str[i] == cur)
seq_is_odd = !seq_is_odd;
else {
if (seq_is_odd) v.push_back(cur);
if (str[i] == '2') {
v.push_back('2');
i++;
}
cur = str[i];
seq_is_odd = true;
}
}
// cout << "Vect: ";
// for (auto i : v) cout << (char)i << ' ';
// cout << endl;
if (s.size() == str.size()) {
cout << s.size() << '\n';
return;
}
for (char c : v) {
if (s.size() && (c == s.top() || s.top() == '2')) s.pop();
else s.push(c);
}
cout << s.size() << '\n';
}
int main() {
int n; cin >> n;
while (n--)
solve();
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3804kb
input:
5 0110101 01020102 0000021111 1012121010 0100202010
output:
3 6 2 6 0
result:
wrong answer 2nd numbers differ - expected: '4', found: '6'