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个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- Apache 隐藏入口文件 index.php
新建 .htaccess文件至站点目录下,并写入如下代码: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQ ...
- 重启机器解决SSL都要输入密码问题
在Nginx或Apache设置了SSL加密后,发现每次重启服务器后都要输入证书设置的密码,比较麻烦,不然Nginx或Apache无法使用,这时可以用私钥来做这件事.生成一个解密的key文件,替代原来k ...
- FZU 2112 Tickets
这个问题可以转变一下,先要知道有几个连通块,连通块之间肯定需要添加一条边, 还需要知道每个连通块内部需要添加几条边,这个问题等价于求一张图至少需要几笔画成,这个问题的答案是度为奇数的点的个数/2 #i ...
- HUST 1606 Naive
预处理一下,然后o(1)询问. #include<cstdio> #include<cstring> #include<cmath> #include<str ...
- MIPI-1
未来的产品都将朝着移动的方向发展,例如智能手机.数码相机.摄像机.平板电脑.媒体播放器.游戏机等,这些产品需要能执行多任务,包括处理多个不同的传感器如麦克风.图像传感器.磁罗盘.三轴加速度计和精细的触 ...
- ios UIKit动力
UIkit动力学是UIkit框架中模拟真实世界的一些特性. UIDynamicAnimator 主要有UIDynamicAnimator类,通过这个类中的不同行为来实现一些动态特性. 它一般有两种初始 ...
- angular中ui calendar的一些使用心得
ui calendar是封装fullcalendar的一款angular指令插件 官方地址:http://angular-ui.github.io/ui-calendar/ fullcalendar ...
- mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: YES)'
就当作自己忘记Mysql密码把,忘记密码的解决方法 一.mysql登录错误mysqladmin: connect to server at 'localhost' failederror: 'Acce ...
- cocos2d动作讲解
从本章开始,我们开始讲解cocos2d-x库的动作(Action).游戏的世界是一个动态的世界:无论是主角精灵还是NPC精灵都处于不断的运动当中,甚至是背景中漂流的树叶,随风而动的小草.这些明显的或者 ...
- Nodejs之使用session
nodejs中使用session的说明. session介绍 为什么使用session: session运行在服务器端,当客户端第一次访问服务器时,可以将客户的登陆信息保存. 当客户访问其他界面时,可 ...