time limit per test1 second

memory limit per test256 megabytes

inputstandard input

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

【题解】



要找到连续的黑色块。输出它的总数以及每个连续块的大小;

为什么这种题的通过率不是100%。。。

#include <cstdio>

const int MAXN = 200;

int n, a[MAXN] = { 0 }, ans[MAXN] = { 0 };
char s[MAXN]; int main()
{
//freopen("F:\\rush.txt", "r", stdin);
scanf("%d", &n);
scanf("%s", s);
for (int i = 1; i <= n; i++)
if (s[i - 1] == 'B')
a[i] = 1;
else
a[i] = 0;
int j = 1, k = 0;
while (j <= n)
{
int temp = j;
if (a[temp] == 1)
{
k++;
while (a[temp + 1] == 1)
temp++;
ans[k] = temp - j + 1;
}
j = temp + 1;
}
printf("%d\n", k);
for (int i = 1; i <= k - 1; i++)
printf("%d ", ans[i]);
if (k > 0)
printf("%d\n", ans[k]);
return 0;
}

【76.57%】【codeforces 721A】One-dimensional Japanese Crossword的更多相关文章

  1. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  2. 【76.83%】【codeforces 554A】Kyoya and Photobooks

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【57.97%】【codeforces Round #380A】Interview with Oleg

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【34.57%】【codeforces 557D】Vitaly and Cycle

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【codeforces 750C】New Year and Rating(做法2)

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【codeforces 750A】New Year and Hurry

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【codeforces 750C】New Year and Rating

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  9. 【搜索】【并查集】Codeforces 691D Swaps in Permutation

    题目链接: http://codeforces.com/problemset/problem/691/D 题目大意: 给一个1到N的排列,M个操作(1<=N,M<=106),每个操作可以交 ...

随机推荐

  1. 3.字符设备驱动------Poll机制

    1.poll情景描述 以之前的按键驱动为例进行说明,用阻塞的方式打开按键驱动文件/dev/buttons,应用程序使用read()函数来读取按键的键值. ) { read(fd, &key_v ...

  2. 免费的EmBitz可替代Keil MDK开发STM32、NXP项目

    一.背景 由于使用之前开发STM32是基于Keil MDK编译环境开发的,由于该软件是收费的,想用个免费开源的软件来替代Keil,EmBitz编译器是免费的,可以完全替代开发.下载程序支持J-Link ...

  3. hdu 2795 Billboard(线段树单点更新)

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. C Tricks(十八)—— 整数绝对值的实现

    为正还是为负:(对 int 类型而言,第一位为符号位,其余为数值,则右移 31 位,再与 1 求与) 如果为正 ⇒ 返回原值 如果为负 ⇒ 对其二进制形式各位取反 + 1 int abs(int x) ...

  5. sql server中新增一条数据后返回该数据的ID

    开发中遇到的问题:在新增一条数据后往往不需要返回该数据的ID,但是有的时候可能需要返回该数据的ID以便后面的编程使用. 在这里介绍两种方法: 其一:使用存储过程: create procedure a ...

  6. zeromq and jzmq

    install c test install jzmq java test Storm UI Cluster Summary Version Nimbus uptime Supervisors Use ...

  7. 机器学习算法中怎样选取超參数:学习速率、正则项系数、minibatch size

    本文是<Neural networks and deep learning>概览 中第三章的一部分,讲机器学习算法中,怎样选取初始的超參数的值.(本文会不断补充) 学习速率(learnin ...

  8. 算法中的优化问题(optimization problem)

    和多数算法不同的是,有些问题的答案不只一个,而是需要在多个答案中,按照一定标准选出"最佳"答案,这类问题就统称为"优化问题"(optimization prob ...

  9. 右键菜单添加带图标的Notepad++

    给Notepad++ 加带图标右键菜单 方式一: 拷贝以下代码建立一个reg文件,替换相关路径,保存,双击运行加入注册表 Windows Registry Editor Version 5.00 [H ...

  10. Python 极简教程(三)数据类型

    每种语言都有各种数据类型.这就像在现实生活中,我们计数的时候需要用到数字,在表述金额.重量.距离等需要精确计数时用到小数,在日常交谈中要用文字,等等.在计算机语言中,为了表述不同的情况,也需要用到各种 ...