Description

You have a string ss of length nn consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).

For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.

The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good.

Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to n−1n−1, but not the whole string). You need to calculate the minimum number of characters to be deleted from string ss so that it becomes good.

Input

The first line contains one integer tt (1≤t≤1001≤t≤100) – the number of test cases. Each test case is represented by two lines.

The first line of ii-th test case contains one integer nn (1≤n≤1001≤n≤100) – the length of string ss.

The second line of ii-th test case contains string ss, consisting of only characters > and <.

Output

For each test case print one line.

For ii-th test case print the minimum number of characters to be deleted from string ss so that it becomes good.

Example

Input

3

2

<>

3

><<

1

>

Output

1

0

0

题目分析

给一个由'>' '<' 组成的字符串,对于'>'可以删除这个字符右边的字符(想到这里,如果'>'在最左边,岂不是可以一次性把右边所有的全部删除),同样,对于'<'可以删除这个字符左边的字符(如果'<'在最右边,也可以将其左边所有的字符全部删除),题目要求通过上面两种变化使得整个字符串只剩下一个字符'>‘或'<',那么根据上面的推理,我们只需要找到最左边的'>'就可以让其后的所有字符全部消失,那么我们只需要删除在'>’左边的所有'<'即可;同理,我们只需要找到最右边的'<'就可以让这个字符前面的所有字符全部消失,那么我们只需要删除在'<’右边的所有>'即可。

由于找到最左边的'>'和最右边的'<'都可以完成任务,所以我们需要这两种解法种需要删除的最小字符,然后输出即可。

代码区

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include <vector>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int Max = 5e5 + 5; char str[Max]; int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n;
scanf("%d", &n);
scanf("%s", str);
if (n == 1)
{
printf("0\n");
continue;
}
int nl = 0, nr = n - 1, x = 0, y = 0;
while (str[nl] == '<')nl++, x++; //找到自左边开始的第一个>号,就可以让这个>号之后的字符全部自动删除,这就是说我们将这个>之前的<全部删除即可
while (str[nr] == '>')nr--, y++; //找到自右边开始的第一个<号,就可以让这个<号之前的字符全部自动删除,这就是说我们将这个<之后的>全部删除即可
int m = x < y ? x : y;
printf("%d\n", m);
}
return 0;
}

CF 1140B Good String的更多相关文章

  1. CF 1131 E. String Multiplication

    E. String Multiplication 题意 分析: 从后往前考虑字符串变成什么样子. 设$S_i = p_1 \cdot p_2 \dots p_{i}$,最后一定是$S_{n - 1} ...

  2. CF 1003B Binary String Constructing 【构造/找规律/分类讨论】

    You are given three integers a, b and x. Your task is to construct a binary string s of length n=a+b ...

  3. CF #541 E. String Multiplication

    题意: 给定一系列字符串,每次都是后一个字符串和前面的融合,这个融合操作就是原来的串分成独立的,然后把新串插入到这些空格中.问最后,最长的相同连续的长度. 思路: 这道题可以贪心的来,我们压缩状态,记 ...

  4. 【CF 710F】String Set Queries

    在校内OJ上A了,没有加强制在线的东西..不放链接了. 这道题题意是维护一个字符串集合,支持三种操作: 1.加字符串 2.删字符串 3.查询集合中的所有字符串在给出的模板串中出现的次数 操作数\(m ...

  5. CF 827E Rusty String FFT

    传送门 如果没有碍事的?的话,判定字符串的循环节直接用KMP的失配数组就可以搞定.现在有了碍事的?,我们就需要考虑更通用的算法. 考虑KMP失配数组判定字符串循环节的本质,发现判定\(k\)是否为字符 ...

  6. (大数 string) Integer Inquiry hdu1047

    Integer Inquiry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. Java中的String字符串及其常用方法

    字符串(String) 文章目录 字符串(String) 直接定义字符串 常用方法 字符串长度 toLowerCase() & toUpperCase()方法 trim()方法去除空格 判空 ...

  8. golang struct扩展函数参数命名警告

    今天在使用VSCode编写golang代码时,定义一个struct,扩展几个方法,如下: package storage import ( "fmt" "github.c ...

  9. OGRE启动过程详解(OGRE HelloWorld程序原理解析)

    本文介绍 OGRE 3D 1.9 程序的启动过程,即从程序启动到3D图形呈现,背后有哪些OGRE相关的代码被执行.会涉及的OGRE类包括: Root RenderSystem RenderWindow ...

随机推荐

  1. hdu_1712(dp,背包)

    hdu_1712 \[dp[i][j]\] 表示前i个物品用了j天得到的最大收益 \[ dp[i][j] = max(dp[i-1][j],dp[i][j-k]+ k*v[i][k]) \qquad ...

  2. 计蒜客T2202 数三角形(提高组2017模拟赛(三)day2T3) LZOJ3878攻略

    今天模拟赛考了一道计蒜客NOIP2017模拟赛(三)day2T3的数三角形,原题链接 https://nanti.jisuanke.com/t/T2202 ,LZOJ3878攻略.场上想了很久都没转化 ...

  3. win10下MYSQL 8.0.16的下载、安装以及配置

    win10系统MySQL 8.0的下载安装超详细教程 https://blog.csdn.net/qq_34444097/article/details/82315587 下载安装配置链接:https ...

  4. 创建Idea创建SpringBoot项目 - 各个目录的解释

    [SpringBoot-创建项目]一.通过Idea创建SpringBoot项目 一.首先我们通过Idea创建一个新项目 二.选择sdk和快速构建模板 三.填写项目基本信息 三.选择项目依赖 四.填写项 ...

  5. C++入门经典-例3.17-使用while循环进行计算

    1:代码如下: // 3.17.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> usin ...

  6. python3笔记三:运算符与表达式

    一:学习内容 算术运算符:+(加).-(减).*(乘)./(除).%(取模).**(求幂).//(取整) 赋值运算符:= 复合运算符:+=.-=.*=./=.%=.**=.//= 位运算符:& ...

  7. 作业要求20191010-3 alpha week 1/2 Scrum立会报告+燃尽图 01

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2019fall/homework/8746 一.小组情况组长:贺敬文组员:彭思雨 王志文 位军营 杨萍队名:胜 ...

  8. UIButton设置按钮点击范围大于可视范围

    自定义按钮类型CustomButton,继承UIButton,重写pointInside函数改变点击响应范围. 例如,按钮点击范围比实际高度上下增加6. CustomButton.h @interfa ...

  9. 一、基础篇--1.1Java基础-Object类中常见的方法,为什么wait notify会放在Object里边

    这是个设计相关的问题,它考察的是面试者对现有系统和一些普遍存在但看起来不合理的事物的看法.回答这些问题的时候,你要说明为什么把这些方法放在Object类里是有意义的,还有不把它放在Thread类里的原 ...

  10. PLSQL导出表的数据insert语句

    “Where clause”可以设置查询条件.设置好文件导出的路径(“Output file”),点击[Export]按钮,就可以导出INSERT语句了. 导出之后使用nodepad打开: 但是如果我 ...