2144.One-dimensional Japanese Crossword

Time Limit: 1s Memory Limit: 256MB

Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized a \times 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 \times n), which he wants to encrypt in the same way as in japanese crossword.
2144_1.png The example of encrypting of a single row of japanese crossword.
Help Adaltik find the numbers encrypting the row he drew.

Input Format(From the terminal/stdin)

The first line of the input contains a single integer n (1 \le n \le 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 Format(To the terminal/stdout)

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.

Sample Input 1

Copy
3
BBW
 \n
   \n

Sample Output 1

Copy
1
2 
 \n
 \n

Sample Input 2

Copy
5
BWBWB
 \n
     \n

Sample Output 2

Copy
3
1 1 1 
 \n
 · · \n

Sample Input 3

Copy
4
WWWW
 \n
    \n

Sample Output 3

Copy
0
 \n

Sample Input 4

Copy
4
BBBB
 \n
    \n

Sample Output 4

Copy
1
4 
 \n
 \n

Sample Input 5

Copy
13
WBBBBWWBWBBBW
  \n
             \n

Sample Output 5

Copy
3
4 1 3 
 \n
 · · \n

Hints

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

Submit

请先 登录

© 2025 FAQs