当前位置: 首页 > news >正文

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要么就是字符串长度。

#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;
}

http://www.dtcms.com/a/33600.html

相关文章:

  • DeepSheek 本地部署
  • Service Worker 实现离线应用思路
  • 简识Kafka集群与RocketMQ集群的核心区别
  • 网络安全研究
  • 在运维工作中,磁盘文件满了,怎么办?
  • 綫性與非綫性泛函分析與應用_2.賦范向量空間-母本
  • Java——抽象类
  • 快速排序与归并排序模板
  • 深入解析DeepSeek智慧城市应用中的交通流量预测API接口
  • 本地部署deepseek-r1 ollama+anythingllm
  • `pip freeze > requirements.txt` 命令
  • 数据治理与管理
  • 从零开始的网站搭建(以照片/文本/视频信息通信网站为例)
  • 大白话React第二章深入理解阶段
  • PTA习题(C语言)
  • Linux——安装Git的方法
  • 一、Spring框架系统化学习路径
  • devops-Jenkins一键部署多台实例
  • 【C++】模版
  • 《AI赋能星际探索:机器人如何开启宇宙新征程!》
  • Milvus向量数据库可视化客户端Attu
  • 基于时间序列的预测方法进行异常值检测概述
  • Element UI日期选择器默认显示1970年解决方案
  • AnythingLLM安装包下载+CUDA安装包下载地址,提升GPU性能【语义熔炉网】
  • Linux系统安装MySQL5.7(其他版本类似)避坑指南
  • 动态记忆网络 DeepMind的MEMO架构允许在推理时动态读写记忆矩阵,记忆容量提升40倍
  • go 查看版本
  • 【2025.2最新版】从零开始的HTML网页开发学习笔记(包含网页基础概念 HTML语法 前端工具VsCode介绍)
  • vLLM学习1
  • 网络安全与措施