zoukankan      html  css  js  c++  java
  • Codeforces Round #180 (Div. 2) A. Snow Footprints(简单)

    A. Snow Footprints
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one.

    At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road.

    You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.

    Input

    The first line of the input contains integer n (3 ≤ n ≤ 1000).

    The second line contains the description of the road — the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).

    It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.

    Output

    Print two space-separated integers — the values of s and t. If there are several possible solutions you can print any of them.

    Sample test(s)
    input
    9
    ..RRLL...
    output
    3 4
    input
    11
    .RRRLLLLL..
    output
    7 5
    Note

    The first test sample is the one in the picture.

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 
     5 using namespace std;
     6 
     7 int main()
     8 {
     9     int n, s, t;
    10     char str[1002];
    11     while(scanf("%d", &n) != EOF)
    12     {
    13         scanf("%s", str + 1);
    14         int len = strlen(str + 1);
    15         bool l = false, r = false;
    16         for(int i = 1; i <= len; i++)
    17         {
    18             if(str[i] == 'L') l = true;
    19             if(str[i] == 'R') r = true;
    20         }
    21         if(l && !r)
    22         {
    23             for(s = len; str[s] == '.'; s--){}
    24             for(t = 1; str[t] == '.'; t++){}
    25             t--;
    26             printf("%d %d\n", s, t);
    27         }
    28         else if(!l && r)
    29         {
    30             for(t = len; str[t] == '.'; t--){}
    31             t++;
    32             for(s = 1; str[s] == '.'; s++){}
    33             printf("%d %d\n", s, t);
    34         }
    35         else
    36         {
    37             for(s = len; str[s] == '.'; s--){}
    38             for(t = s - 1; str[t] == str[s]; t--){}
    39             t++;
    40             if(str[s] == 'L') printf("%d %d\n", s, t);
    41             else printf("%d %d\n", t, s);
    42         }
    43     }
    44     return 0;
    45 }
  • 相关阅读:
    给Array本地对象增加一个原型方法,它用于删除数组条目中重复的条目(可能有多个),返回值是一个包含被删除的重复条目的新数组以及删除了重复条目的原数组。
    mysql批量替换某个字段的值!
    LInux常用命令
    盒模型布局
    box-sizing -- 盒模型
    vue中使用svg字体图标
    字体图标
    在线字体
    Java QQ邮箱发送邮件
    Java 对全局用户是否登录验证
  • 原文地址:https://www.cnblogs.com/cszlg/p/3085484.html
Copyright © 2011-2022 走看看