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;
}
相关推荐
Pacify_The_North2 分钟前
【进程控制二】进程替换和bash解释器
linux·c语言·开发语言·算法·ubuntu·centos·bash
轮到我狗叫了23 分钟前
力扣310.最小高度树(拓扑排序,无向图),力扣.加油站力扣.矩阵置零力扣.二叉树中的最大路径和
算法·leetcode·职场和发展
埃菲尔铁塔_CV算法26 分钟前
深度学习驱动下的目标检测技术:原理、算法与应用创新(二)
深度学习·算法·目标检测
wuqingshun31415929 分钟前
经典算法 (A/B) mod C
c语言·开发语言·c++·算法·蓝桥杯
白杆杆红伞伞32 分钟前
04_决策树
算法·决策树·机器学习
爱coding的橙子36 分钟前
算法刷题Day9 5.18:leetcode定长滑动窗口3道题,结束定长滑动窗口,用时1h
算法·leetcode·职场和发展
姬公子52140 分钟前
leetcodehot100刷题——排序算法总结
数据结构·c++·算法·排序算法
AndrewHZ1 小时前
【图像处理基石】OpenCV中都有哪些图像增强的工具?
图像处理·opencv·算法·计算机视觉·滤波·图像增强·颜色科学
KangkangLoveNLP1 小时前
Llama:开源的急先锋
人工智能·深度学习·神经网络·算法·机器学习·自然语言处理·llama
z人间防沉迷k2 小时前
贪心、分治和回溯算法
算法