A. Iskander and Drawings

time limit per test

1 second

memory limit per test

256 megabytes

During a geometry lesson, Iskander got very bored, so he decided to draw in Yura's notebook. To do this, he took a row and drew horizontal lines on it. Some lines are long, some are short, and some parts of the page remain empty.

The page is represented by a string s, where the character '*' denotes an empty part of the paper, and the character '#' denotes one centimeter of a drawn line. A continuous sequence of '#' characters forms a single line.

Yura decided to erase all the lines and made Iskander help him: they will erase one of the lines from both ends simultaneously.

  • Each second, Iskander erases 1 centimeter from the right end of the line, and Yura erases 1 centimeter from the left end.
  • If the current length of the line is 1 or 2 centimeters, then in the next second it is erased completely, and the process ends.

Yura wants to choose a line so that, together with Iskander, they erase it for as long as possible. Help him determine this maximum time. If there are no lines on the page, the answer is 0 seconds.

Input

The first line contains a single integer t (1≤t≤2500) --- the number of test cases.

The first line of each test case contains an integer n (1≤n≤10) --- the length of the string s.

The second line of each test case contains a string s of length n, consisting of characters '#' and '*'.

Output

For each test case, output a single integer --- the maximum time required to erase a line.

Example

Input

Copy

复制代码

5

7

#*##*##

8

########

8

********

8

#*****##

6

*#####

Output

Copy

复制代码

1

4

0

1

3

解题说明:水题,找出字符串中最长连续出现的#子串,然后除以2即可。

cpp 复制代码
#include<stdio.h>
int main()
{
	int zz;
	scanf("%d", &zz);
	for (int z = 0; z < zz; z++)
	{
		int n;
		scanf("%d", &n);
		char a[20];
		scanf("%s", a);
		int max = 0, count = 0;
		for (int i = 0; i < n; i++)
		{
			if (a[i] == '#') 
			{
				count++;
				if (count > max)
				{
					max = count;
				}
			}
			else
			{
				count = 0;
			}
		}
		printf("%d\n", (max + 1) / 2);
	}
	return 0;
}
相关推荐
qq_348231854 小时前
大模型算法: 反向传播
算法
电科_银尘4 小时前
【大模型算法与工程 27】训练配方:批量、学习率、精度与梯度裁剪
学习·算法·机器学习
专注仿真5 小时前
智能体训练之模仿学习:GAIL 算法详解与实战
python·算法·仿真·多智能体强化学习·afsim智能体训练
leobertlan7 小时前
痛苦系列 | DSP-04 截断时空的“窗”:FIR 滤波器设计与线性相位
算法
秋天的怀念_David8 小时前
算法一千零一夜 · 第三十五夜 · 恢复风暴
java·程序人生·算法
泯泷10 小时前
别再“裸聊”大模型了!你家的 AI 为什么总胡说八道?根子在 RAG
人工智能·算法·架构
2601_9679801111 小时前
Python中heapq模块的各种用法实例
数据结构·python·算法·应用实例·heapq模块
漂流瓶jz13 小时前
UVA-1615 高速公路 题解答案代码 算法竞赛入门经典第二版
数据结构·算法·贪心算法·贪心·aoapc·算法竞赛入门经典·uva