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;
}
相关推荐
8Qi81 小时前
LeetCode 75:颜色分类(荷兰国旗问题)—— Java 题解 ✅
java·算法·leetcode·指针·排序
888CC++3 小时前
如何在 C 语言中进行程序调试?
前端·javascript·算法
(●—●)橘子……4 小时前
力扣第503场周赛练习理解
python·学习·算法·leetcode·职场和发展·周赛
明志数科6 小时前
4D时序标注技术详解:让机器人理解连续动作的数据基础
java·算法·机器人
KaMeidebaby6 小时前
卡梅德生物技术快报|原核表达系统工艺优化:包涵体重折叠 + 分子筛纯化实现功能 RBD 高效制备,附全参数配置
前端·人工智能·算法·数据挖掘·数据分析
无限码力7 小时前
携程0510笔试真题【单数组交换】
算法·携程笔试·携程笔试真题·携程0510笔试真题
BlockWay7 小时前
WEEX Labs 周度观察:微软-OpenAI 合作调整与AI 多云趋势
大数据·人工智能·算法·安全·microsoft
风筝在晴天搁浅7 小时前
快手 CodeTop LeetCode 224.基本计算器
数据结构·算法·leetcode
Smoothcloud润云8 小时前
5大功能精修,重构AI算力使用体验!
java·人工智能·windows·算法·重构·编辑器·sublime text