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;
}
相关推荐
爪哇部落算法小助手34 分钟前
每日两题day44
算法
不穿格子的程序员1 小时前
从零开始写算法——二分-搜索二维矩阵
线性代数·算法·leetcode·矩阵·二分查找
Kuo-Teng2 小时前
LeetCode 19: Remove Nth Node From End of List
java·数据结构·算法·leetcode·链表·职场和发展·list
Kuo-Teng2 小时前
LeetCode 21: Merge Two Sorted Lists
java·算法·leetcode·链表·职场和发展
2301_800399722 小时前
stm32 printf重定向到USART
java·stm32·算法
顾安r3 小时前
11.15 脚本算法 加密网页
服务器·算法·flask·html·同态加密
前端小L4 小时前
图论专题(四):DFS的“回溯”之舞——探寻「所有可能路径」
算法·深度优先·图论
司铭鸿4 小时前
数学图论的艺术:解码最小公倍数图中的连通奥秘
运维·开发语言·算法·游戏·图论
元亓亓亓4 小时前
LeetCode热题100--39. 组合总和
算法·leetcode·职场和发展
2401_841495644 小时前
【LeetCode刷题】找到字符串中所有字母异位词
数据结构·python·算法·leetcode·数组·滑动窗口·找到字符串中所有字母异位词