CodeForces 725A
A. Jumping Ball
256 megabytes
standard input
standard output
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.
Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper.
Output
Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position.
Examples
input
4
<<><
output
2
input
5
>>>>>
output
5
input
4
>><<
output
0
Note
In the first sample, the ball will fall from the field if starts at position 1 or position 2.
In the second sample, any starting position will result in the ball falling from the field.
从左端数'<'个数与从右端数‘>’个数即可
//2016.11.01
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int N = ;
char arr[N]; int main()
{
int n, ans;
while(scanf("%d", &n)!=EOF)
{
scanf("%s", arr);
ans = ;
for(int i = ; i < n; i++)
{
if(arr[i] == '>')break;
ans++;
}
for(int i = n-; i >= ; i--)
{
if(arr[i] == '<')break;
ans++;
}
printf("%d\n", ans);
} return ;
}
CodeForces 725A的更多相关文章
- CodeForces Canada Cup 2016【A,B,C,D】
CodeForces 725A: 思路就是如果"最左"不是'>'这个了,那么这个右边的一定不可能到达左边了: 同理最右: CodeForces 725B: 有两个空姐,一个从 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- php 中的全局变量的理解
$GLOBALS 是php中的一个全局变量的数组. $GLOBALS['var1'] 代表的是 外部的全局变量 $var1 本身.global $var是外部$var的同名引用或者指针 例1: &l ...
- IO之同步、异步、阻塞、非阻塞
Stevens在文章中一共比较了五种IO Model: blocking IO nonblocking IO IO multiplexing signal driven IO ...
- (中等) HDU 4979 A simple math problem. , DLX+重复覆盖+打表。
Description Dragon loves lottery, he will try his luck every week. One day, the lottery company brin ...
- [Unity AssetBundle]Asset资源处理
什么是AssetBundle 在很多类型游戏的制作过程中,开发者都会考虑一个非常重要的问题,即如何在游戏运行过程中对资源进行动态的下载和加载.因此,Unity引擎引入了AssetBundle这一技术来 ...
- stm32 Bootloader设计(YModem协议) (转)
源:stm32 Bootloader设计(YModem协议) 相信很多人都希望,不开盖就可以对固件进行升级吧,就像手机那些.下文中的bootload就来实现这样的功能. 前段时间有项目关于Bootlo ...
- iOS自定义字体及类目
1:获取字体文件 从各种渠道下载字体文件ttf, 网站或者从别的ipa里扣出来.(以fzltxh.ttf为例) 2:将fzltxh.ttf文件拷贝到工程中 3:在Info.plist中添加项: Fon ...
- JV的DOM操作
一.基本概念 :是文档对象模型,这种模型为树模型:文档指标签文档:对象是指文档中每个元素:模型是指抽象化的东西. :.Windows对象操作:.属性:opener:(打开当前窗口的原窗口.)dialo ...
- java 正则匹配int型
private static Pattern DIGIT_PATTERN = Pattern.compile("=\\d++"); Matcher goodsTypeMatcher ...
- ios数据存储——数据库:SQlite3以及第三方库FMDB
[reference]http://blog.csdn.net/mad1989/article/details/9322307 原生数据库:SQlite3 一.必备条件 在ios项目中使用sqlite ...
- uWSGI参考资料(1.0版本的配置选项列表)
Reference: http://blog.csdn.net/kevin6216/article/details/15378617 uWSGI参考资料(1.0版本的配置选项列表) 下面的内容包含了大 ...