zoukankan      html  css  js  c++  java
  • CodeForces 725A

    A. Jumping Ball

    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    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.

    从左端数'<'个数与从右端数‘>’个数即可

     1 //2016.11.01
     2 #include <iostream>
     3 #include <cstdio>
     4 #include <cstring>
     5 
     6 using namespace std;
     7 
     8 const int N = 200005;
     9 char arr[N];
    10 
    11 int main()
    12 {
    13     int n, ans;
    14     while(scanf("%d", &n)!=EOF)
    15     {
    16         scanf("%s", arr);
    17         ans = 0;
    18         for(int i = 0; i < n; i++)
    19         {
    20             if(arr[i] == '>')break;
    21             ans++;
    22         }
    23         for(int i = n-1; i >= 0; i--)
    24         {
    25             if(arr[i] == '<')break;
    26             ans++;
    27         }
    28         printf("%d
    ", ans);
    29     }
    30 
    31     return 0;
    32 }
  • 相关阅读:
    sql 生成javabean实体
    git 安装 使用过程遇到的问题
    CentOS7 ab压力测试安装
    Lvs+keepalived+mysql(主从复制)
    liunx下tomcat启动 Cannot find ./catalina.sh
    ftp和ssh登录缓慢的解决办法
    Contos7 FTP 安装步骤
    python生成100以内格式化的数
    Windows中更新python模块的命令
    scrapy的User-Agent中间件、代理IP中间件、cookies设置、多个爬虫自定义settings设置
  • 原文地址:https://www.cnblogs.com/Penn000/p/6021274.html
Copyright © 2011-2022 走看看