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

    A. One-dimensional Japanese Crossword

    time limit per test:1 second
    memory limit per test:256 megabytes
    input:standard input
    output:standard output

    Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized a × b squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia https://en.wikipedia.org/wiki/Japanese_crossword).

    Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of n squares (e.g. japanese crossword sized 1 × n), which he wants to encrypt in the same way as in japanese crossword.

    The example of encrypting of a single row of japanese crossword.

    Help Adaltik find the numbers encrypting the row he drew.

    Input

    The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the length of the row. The second line of the input contains a single string consisting of n characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).

    Output

    The first line should contain a single integer k — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.

    The second line should contain k integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.

    Examples

    input

    3
    BBW

    output

    1
    2

    input

    5
    BWBWB

    output

    3
    1 1 1

    input

    4
    WWWW

    output

    0

    input

    4
    BBBB

    output

    1
    4

    input

    13
    WBBBBWWBWBBBW

    output

    3
    4 1 3

    Note

    The last sample case correspond to the picture in the statement.

    第一次打cf,签到题,问黑色块的个数和长度

     1 //2016.9.30
     2 #include <iostream>
     3 #include <cstdio>
     4 #include <cstring>
     5 #define N 105
     6 
     7 using namespace std;
     8 
     9 string str;
    10 int ans[N];
    11 
    12 int main()
    13 {
    14     int n, cnt, tmp;
    15     while(scanf("%d", &n)!=EOF)
    16     {
    17         tmp = cnt = 0;
    18         cin>>str;
    19         int len = str.length();
    20         for(int i = 0; i < len; i++)
    21         {
    22             if(str[i]=='B')
    23             {
    24                 tmp = 0;
    25                 while(str[i]=='B'&&i<n)
    26                 {
    27                     i++;
    28                     tmp++;
    29                 }
    30                 ans[cnt++] = tmp;
    31             }
    32         }
    33         cout<<cnt<<endl;
    34         for(int i = 0; i < cnt; i++)
    35         {
    36             if(i==0)cout<<ans[i];
    37             else cout<<" "<<ans[i];
    38         }
    39         if(!cnt)cout<<endl;
    40     }
    41     return 0;
    42 }
  • 相关阅读:
    java
    java
    java
    java
    java
    java
    java
    java
    sed命令的用法
    linux系统产生随机数的6种方法
  • 原文地址:https://www.cnblogs.com/Penn000/p/5925561.html
Copyright © 2011-2022 走看看