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 }
  • 相关阅读:
    pymongo
    活动专题,各种手机的适配
    怎么判断是qq浏览器还是uc浏览器?
    并的用法,存在并执行~~
    window.location.href在微信端不起作用的解决方法?
    div双击全屏,再双击恢复到原来的状态vue,js来做
    avalon结合原生js tab切换
    vue指令大全~~~
    jquery中$.get()如何让跨域请求携带cookie?
    git 的使用方法以及要注意的地方~/git stash的使用
  • 原文地址:https://www.cnblogs.com/cszlg/p/3085484.html
Copyright © 2011-2022 走看看