QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#793526 | #9430. Left Shifting 2 | 2317663977 | WA | 0ms | 3592kb | C++23 | 1.1kb | 2024-11-29 20:49:03 | 2024-11-29 20:49:04 |
Judging History
answer
#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <cstring>
using ll = long long;
string s;
bool judge()
{
for (int i = 1;i < s.size();i++)
if (s[i] != s[0])
return false;
return true;
}
void solve()
{
cin >> s;
if (judge())
{
cout << s.size() / 2 << '\n';
return;
}
int ans = 0;
int now = 1;
int ft = 0, ed = 0;
for (int i = 1;i < s.size();i++)
{
if (s[i] == s[i - 1]) now++;
else
{
ans += now / 2;
if (ft == 0) ft = now;
ed = now;
now = 1;
}
}
ans += now / 2;
if (ft == 0) ft = now;
ed = now;
now = 1;
if (ans == 0) cout << 0 << '\n';
else
{
if (s[0] == s[s.size() - 1])
{
if (ft % 2 == 0 && ed % 2 == 0) cout << max(ans - 1, 1) << '\n';
else cout << ans << '\n';
}
else
{
if (ft % 2 == 1 && ed % 2 == 1) cout << ans << '\n';
else cout << max(ans - 1, 1) << '\n';
}
}
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int T = 1;
cin >> T;
while (T--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3592kb
input:
3 abccbbbbd abcde x
output:
3 0 0
result:
wrong answer 1st lines differ - expected: '2', found: '3'