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 }
  • 相关阅读:
    明就要发布一加8pro了,发几张关于7的图片供大家回忆下
    【移动端开发】移动端开发项目架构
    【前端开发】three.js入门
    【前端依赖】live-server静态文件本热更新静态服务安装及使用教程
    【vue开发】泛型总结
    【vue前端开发】微信扫码登录
    【正则表达式】梳理
    【mock数据服务】大项目中mock的使用方法和注意事项
    【vue开发】v-bind="$attrs" v-on="$listeners" 多层组件监听
    【vue开发】render的用法,全局引入/组件简化代码
  • 原文地址:https://www.cnblogs.com/cszlg/p/3085484.html
Copyright © 2011-2022 走看看