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 }
  • 相关阅读:
    前端如何进阶架构师
    NPOI使用记录
    ArcGis 中空间数据的插入与更新
    (转载).net 缓存处理
    ASP.NET(c#)实现重定向的三种方法的总结
    数据库关联表之间的更新语句
    C#net多线程多文件压缩下载
    关于写文件流的情况
    C# Class获取项目的绝对路径
    C# .net中DatailsView的JS简易版
  • 原文地址:https://www.cnblogs.com/cszlg/p/3085484.html
Copyright © 2011-2022 走看看