CF721A.One-dimensional Japanese Crossword

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

最近,Adaltik 发现了日本填字游戏(又称“非ogram”或“数织”)。日本填字游戏是一幅由 a×ba \times b 个方格组成的图像,每个方格被涂成白色或黑色。在每行左侧及每列上方都标有一些整数,用于对相应行或列进行编码。这些整数的个数表示该行或该列中黑色方格的连续段(即连续的黑色方格组成的组)的数目;而每个整数本身则表示对应连续段中黑色方格的数量(更详细的解释可参见维基百科:https://en.wikipedia.org/wiki/Japanese_crossword)。

Adaltik 认为一般情形下的日本填字游戏过于复杂,于是他仅画出了一行共 nn 个方格的图案(即尺寸为 1×n1 \times n 的日本填字游戏),并希望以与标准日本填字游戏相同的方式对该行进行编码。

日本填字游戏中单行编码的一个示例。

请帮助 Adaltik 找出用于编码他所画这一行的数字序列。

输入格式

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).

输入的第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100)—— 表示该行的长度。
输入的第二行包含一个由 nn 个字符组成的字符串,每个字符为 'B' 或 'W'(其中 'B' 对应 Adaltik 所画行中的黑色方格,'W' 对应白色方格)。

输出格式

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.

第一行应包含一个整数 kk —— 加密该行的整数个数,即该行中黑色方块组的数量。

第二行应包含 kk 个整数,用于加密该行,即从左到右依次对应各连续黑色方块组的长度。

输入输出样例

  • 输入#1

    3
    BBW

    输出#1

    1
    2
  • 输入#2

    5
    BWBWB

    输出#2

    3
    1 1 1
  • 输入#3

    4
    WWWW

    输出#3

    0
  • 输入#4

    4
    BBBB

    输出#4

    1
    4
  • 输入#5

    13
    WBBBBWWBWBBBW

    输出#5

    3
    4 1 3

说明/提示

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

最后一个样例对应题目陈述中的图片。

输入解题思路,AI测评打分。不知道怎么写?

首页