QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#793526#9430. Left Shifting 22317663977WA 0ms3592kbC++231.1kb2024-11-29 20:49:032024-11-29 20:49:04

Judging History

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

  • [2024-11-29 20:49:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3592kb
  • [2024-11-29 20:49:03]
  • 提交

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'