CF:B. Comparison String

You are given a string ss of length nn, where each character is either < or >.

An array aa consisting of n+1 elements is compatible with the string ss if, for every i from 1 to nn, the character sisi represents the result of comparing aiai and ai+1, i. e.:

  • si is < if and only if ai<ai+1
  • si is > if and only if ai>ai+1

For example, the array [1,2,5,4,2] is compatible with the string <<>>. There are other arrays with are compatible with that string, for example, [13,37,42,37,13]

The cost of the array is the number of different elements in it. For example, the cost of[1,2,5,4,2] is 4; the cost of [13,37,42,37,13] is 3.

You have to calculate the minimum cost among all arrays which are compatible with the given string ss.

Input

The first line contains one integer tt (1≤t≤500) — the number of test cases.

Each test case consists of two lines:

  • the first line contains one integer n (1≤n≤100);
  • the second line contains the string ss, consisting of n characters. Each character of s is either < or >.

Output

For each test case, print one integer — the minimum cost among all arrays which are compatible with the given string s

#include <bits/stdc++.h>
using namespace std;
int n, t;
string s;
int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout.tie(0);
    cin >> t;
    while(t--)
    {
        cin >> n;
        cin >> s;
        int cnt = 1;
        int ans = cnt;
        for(int i = 1; i < n;i++)
        {
            if(s[i] == s[i - 1])
            {
                cnt++;
            }
            else
            {
                cnt = 1;
            }
            ans = max(cnt,ans);
        }
        cout << ans + 1 << endl;

    }


    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值