B. Skibidus and Ohio

time limit per test

1 second

memory limit per test

256 megabytes

Skibidus is given a string ss that consists of lowercase Latin letters. If ss contains more than 11 letter, he can:

  • Choose an index ii (1≤i≤|s|−11≤i≤|s|−1, |s||s| denotes the current length of ss) such that si=si+1si=si+1. Replace sisi with any lowercase Latin letter of his choice. Remove si+1si+1 from the string.

Skibidus must determine the minimum possible length he can achieve through any number of operations.

Input

The first line contains an integer tt (1≤t≤1001≤t≤100) --- the number of test cases.

The only line of each test case contains a string ss (1≤|s|≤1001≤|s|≤100). It is guaranteed ss only contains lowercase Latin letters.

Output

For each test case, output an integer on the new line, the minimum achievable length of ss.

Example

Input

Copy

复制代码

4

baa

skibidus

cc

ohio

Output

Copy

复制代码
1
8
1
4

Note

In the first test case, Skibidus can:

  • Perform an operation on i=2i=2. He replaces s2s2 with b and removes s3s3 from the string. Then, ss becomes bb.
  • Perform an operation on i=1i=1. He replaces s1s1 with b and removes s2s2 from the string. Then, ss becomes b.
  • Because ss only contains 11 letter, Skibidus cannot perform any more operations.

Therefore, the answer is 11 for the first test case.

In the second test case, he cannot perform an operation on any index. Therefore, the answer is still the length of the initial string, 88.

解题说明:此题是一道字符串题,找规律能发现,只要存在两个连续相同的字母就能继续执行,因为每次删除时都能将选中的字母变成前面的字母,这样就能不断删除后面的字母,直到为1,所以答案要么为1要么就是字符串长度。

cpp 复制代码
#include<stdio.h>
#include<string.h>
int n;
char a[111];
int main() 
{
	scanf("%d", &n);
	while (n--) 
	{
		scanf("%s", a);
		int t = strlen(a);
		int flag = 1;
		for (int i = 0; i < t - 1; i++) 
		{
			if (a[i] == a[i + 1])
			{
				printf("1\n");
				flag = 0;
				break;
			}
		}
		if (flag)
		{
			printf("%d\n", t);
		}
		memset(a, '\0', sizeof(a));
	}
	return 0;
}
相关推荐
山峰哥10 分钟前
沉浸式翻译插件深度评测:打破语言壁垒的黑科技利器
数据结构·科技·算法·编辑器·办公
AI脚下的巨人22 分钟前
机器人逆运动学:从SVD到IK算法
算法·机器人
ゞ 正在缓冲99%…1 小时前
2025.9.28华为软开
算法·华为
9ilk2 小时前
【C++】 --- 哈希
c++·后端·算法·哈希算法
再卷也是菜3 小时前
C++篇(21)图
数据结构·c++·算法
星轨初途3 小时前
C++入门(算法竞赛类)
c++·经验分享·笔记·算法
灰灰勇闯IT4 小时前
KMP算法在鸿蒙系统中的应用:从字符串匹配到高效系统级开发(附实战代码)
算法·华为·harmonyos
小龙报4 小时前
【算法通关指南:数据结构和算法篇 】队列相关算法题:3.海港
数据结构·c++·算法·贪心算法·创业创新·学习方法·visual studio
csuzhucong4 小时前
一阶魔方、一阶金字塔魔方、一阶五魔方
算法
五花就是菜4 小时前
P12906 [NERC 2020] Guide 题解
算法·深度优先·图论