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. Confluence 6 Office 和 PDF 文件

    插入一个文件到页面中是能够让你将有用的文件,电子表格,幻灯片或者其他可用的文件在你小组中进行分享的好方法. 针对所有的文件类型,你可以选择以链接方式插入一个文件.缩略图将会对文档的内容进行预览同时可以 ...

  2. CodeForces 352C Jeff and Rounding

    题意 有一个含有\(2n(n \leqslant2000)\)个实数的数列,取出\(n\)个向上取整,另\(n\)个向下取整.问取整后数列的和与原数列的和的差的绝对值. 就是说,令\(a\)为原数列, ...

  3. iview简单使用+按需加载组件的方法(全局和局部)

    1,简单使用 vue项目中使用iview非常简单: 首先安装依赖: $ npm install iview --save 会安装最新版本的依赖,安装完成后package.json会出现如下图配置 表示 ...

  4. sqli-labs(4)

    sqli-libs(4)通关过程 0x01爱之初体验 首先我们进行注入试探 发现我们的单引号 回显事正常的 双引号回显反而是错误的 查看源码我们发现 多了一个给id赋值的语句 我们在php上面执行一下 ...

  5. kali修改更新源及更新

    进入源文件进行修改 leafpad /etc/apt/sources.list (其实系统本身就自带了更新源,去掉其注释也是可以的,现在官方源的下载速度也还ok,下面的三选一亦可) #kali官方源 ...

  6. MyBatis中的JdbcType映射介绍

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.                                               本 ...

  7. jsPDF生成pdf文件和中文编码

    jsPDF的简单使用以及中文编码问题的解决 文中js通过CDN引入,若是为了加载时间最好下载至本地. jsPDF的使用 jsPDF简介 jsPDF 是一个基于 HTML5 的客户端解决方案,用于在客户 ...

  8. axios 的用法解析

    axios 的非常好的请求数据方式,利用了 promise 的方式来进行的操作 首先 promise 是非常好的处理 异步请求的方式,且拥有高并发请求的能力 并发请求:出现大量的异步请求后,一起处理 ...

  9. leetcode-easy-string-7 Reverse Integer

    mycode class Solution(object): def reverse(self, x): """ :type x: int :rtype: int &qu ...

  10. latexdiff中的大坑:字符编码问题

    最近用latex写文章,要用到修订模式,于是采用latexdiff命令生成修订版pdf.这原本是一个非常简单方便的方法,却隐藏着字符编码的问题,初次用可能会遇到意想不到的问题,让人很烦,比如,生成出来 ...