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,签到题,问黑色块的个数和长度

 //2016.9.30
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 105 using namespace std; string str;
int ans[N]; int main()
{
int n, cnt, tmp;
while(scanf("%d", &n)!=EOF)
{
tmp = cnt = ;
cin>>str;
int len = str.length();
for(int i = ; i < len; i++)
{
if(str[i]=='B')
{
tmp = ;
while(str[i]=='B'&&i<n)
{
i++;
tmp++;
}
ans[cnt++] = tmp;
}
}
cout<<cnt<<endl;
for(int i = ; i < cnt; i++)
{
if(i==)cout<<ans[i];
else cout<<" "<<ans[i];
}
if(!cnt)cout<<endl;
}
return ;
}

CodeForces 721A的更多相关文章

  1. CodeForces 721A One-dimensional Japanese Crossword (水题)

    题意:给定一行字符串,让你输出字符‘B'连续出现的次数. 析:直接扫一下就OK了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024 ...

  2. 【76.57%】【codeforces 721A】One-dimensional Japanese Crossword

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

  3. Codeforces水题集合[14/未完待续]

    Codeforces Round #371 (Div. 2) A. Meeting of Old Friends |B. Filya and Homework A. Meeting of Old Fr ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. html5 canvas 实现简单的画图

    今天早上看了一下 canvas 前端画图,数据可视化, 百度的 echart.js  , d3等 js 库都已经提供了强大的绘制各种图形的 API. 下面记录一下 有关canvas 绘图的基本知识: ...

  2. CodeForces 609C Load Balancing

    先算出目标状态,然后拿当前状态与目标状态对比,即可算出答案 #include<cstdio> #include<cmath> #include<cstring> # ...

  3. openstack controller ha测试环境搭建记录(四)——配置mysql数据库集群

    内容正式开始前,我已经在集群中添加了新的节点controller1(IP地址为10.0.0.14). 在所有节点上安装软件:# yum install -y mariadb-galera-server ...

  4. 编写一个python脚本功能-备份

    版本一 解决方案当我们基本完成程序的设计,我们就可以编写代码了,它是对我们的解决方案的实施.版本一例10.1 备份脚本——版本一 #!/usr/bin/python # Filename: backu ...

  5. 原生js的各种方法

    原生js操作dom元素 var link = document.createElement( "link" );link.type = "image/x-icon&quo ...

  6. jvm 配置,看看

    http://my.oschina.net/qiangzigege/blog/661757

  7. mustache.js使用基本(三)

    作者:zccst 本节要点是子模块(partials)和分隔符(delimiter)等 1,子模块(partials) /* {{>partials}}以>开始表示子模块,如{{> ...

  8. OPENCV形态学算法-2

    一.漫水填充算法 该算法通过一个指定的种子点,来分析整张图片上的像素,并设置像素差异阈值,在阈值类的点,最后变成相同的颜色.该方法通过上下限和连通方式来达到不同的连通效果. 该方法常用与标记和分离图像 ...

  9. Solr 按照得分score跟指定字段相乘排序

    sort=product([you_field],query($q)) desc

  10. D Vitamin - the wonder vitamin

    原文 Be healthier and happier by spending time in the sun In the dead of winter,we don't typically thi ...