A. Jumping Ball
来源:互联网 发布:dj舞曲视频软件 编辑:程序博客网 时间:2024/05/21 06:16
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of nbumpers. 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.
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.
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.
4<<><
2
5>>>>>
5
4>><<
0
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.
解题说明:此题是一道堆栈题,按照要求模拟进栈出栈即可。
#include<cstdio>#include <cstring>#include<cmath>#include<iostream>#include<algorithm>#include<vector>#include <map>using namespace std;int main(){char a[200000];int n,i;int pos=0;scanf("%d",&n);scanf("%s",a);for(i=0;i<n;i++){if(a[i]=='<'){pos++;}else{break;}}for(i=n-1;i>=0;i--){if(a[i]=='>'){pos++;}else{break;}}printf("%d\n",pos);return 0;}
- A. Jumping Ball
- 725A Jumping Ball
- Codeforces 725A Jumping Ball
- CodeForces 725A Jumping Ball
- codeforces 725A Jumping Ball(水)
- Codeforces 725 A Jumping Ball【水题】
- Canada Cup 2016 A - Jumping Ball
- code forces A. Jumping Ball (水题)
- Canada Cup 2016 A.Jumping Ball并查集 .
- Canada Cup 2016 A. Jumping Ball codeforces(水题)
- Canada Cup 2016 A - Jumping Ball (枚举水题)
- A simple bouncing ball
- A. Ball Game
- ROLL A BALL 小游戏
- Roll a Ball
- Roll a Ball
- UVA11880 Ball in a Rectangle
- Unity3D-Roll-a-ball(1)
- 关于RecyclerView的一些使用见解以及使用过程中踩过的一些坑
- android联系人的简易通讯录
- 并发和并行
- 正则表达式
- js立即执行函数
- A. Jumping Ball
- Java的第一月
- linux如何禁ping和允许ping设置方法
- uCOS-III阅读,第一天,也就瞎看看
- Grumpy: Go 运行 Python
- iOS学习笔记-031.数据的读取——沙盒模型
- 利用类的成员函数重载双目运算符其最多只有一个参数
- OS_Init
- LeetCode 453. Minimum Moves to Equal Array Elements