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. LOJ #2718. 「NOI2018」归程 Dijkstra+可持久化并查集

    把 $Noi2018$ day1t1 想出来还是挺开心的,虽然是一道水题~ 预处理出来 1 号点到其它点的最短路,然后预处理边权从大到小排序后加入前 $i$ 个边的并查集. 这个并查集用可持久化线段树 ...

  2. 51 Nod 1089 最长回文子串(Manacher算法)

    1089 最长回文子串 V2(Manacher算法)  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 回文串是指aba.abba.cccbccc.aaa ...

  3. [HG]子树问题 题解

    前言 模拟赛赛时SubtaskR3没开long long丢了20分. 题意简述 题目描述 对于一棵有根树(设其节点数为 \(n\) ,则节点编号从 \(1\) 至 \(n\) ),如果它满足所有非根节 ...

  4. C++ list用法总结

    头文件 #include<list> 声明一个int型的list:list a: 1.list的构造函数 list<int>a{1,2,3} list<int>a( ...

  5. Python实用黑科技——找出序列里面出现次数最多的元素

    需求: 如何从一个序列中快速获取出现次数最多的元素. 方法: 利用collections.Counter类可以解决这个问题,特别是他的most_common()方法更是处理此问题的最快途径.比如,现在 ...

  6. RedisTemplate 用法

      Redis 数据结构简介 Redis 可以存储键与5种不同数据结构类型之间的映射,这5种数据结构类型分别为String(字符串).List(列表).Set(集合).Hash(散列)和 Zset(有 ...

  7. Java常考面试题整理(四)

    有关所有Swing相关的面试题,都可以说是凑数的,感觉自己在敲这些的时候感觉一点用处都没有,可以从第72条开始看. 61.说出三种支持重绘(painting)的组件. 参考答案: Canvas,Fra ...

  8. 数据加密之RSA

    特别提示:本人博客部分有参考网络其他博客,但均是本人亲手编写过并验证通过.如发现博客有错误,请及时提出以免误导其他人,谢谢!欢迎转载,但记得标明文章出处:http://www.cnblogs.com/ ...

  9. DS博客大作业--树 (陈梓灿组)

    1.树的存储结构说明 定义的结构体中,name是用于存放文件名称,string类型是字符串类型,定义了child孩子结点和brother兄弟结点. 2.树的函数说明 1.main函数 main函数中主 ...

  10. java 对象引用为null时,出现的bug问题

    在Java中,对象往往包含属性.方法及一个存储空间,若一个对象的属性和方法是空的则可认为这是一个空对象. 一个空对象也是对象,同样通过对象名引用方法或属性,但和一般对象有点不同. 1.空对象调用非静态 ...