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

    test fsdfs jsjf sdfsdfsdfsdf sfs fsfsfs test112 sdfs sdfsdf sdfs sf af s sdf sadfasdfsa asfasf sdfsa ...

  2. c语言学习基础:[1]开发工具介绍

    标签:c语言 1 2 3 4 分步阅读 学习编程语言的童鞋们一开始接触到的最多的估计就是C语言了,其次才是什么java.c++等,可以说学习c语言是我们走向编程世界的一座桥梁,学好它,对于我们学习和研 ...

  3. Unity3d之shaderLab内置变量

    float4 _WorldSpaceCameraPos camera在世界坐标系中的位置float4 _WorldSpaceLightPos0 灯光在世界坐标系中的位置 转载请注明出处: http:/ ...

  4. Gradle依赖项学习总结,dependencies、transitive、force、exclude的使用与依赖冲突解决

    http://www.paincker.com/gradle-dependencies https://docs.gradle.org/current/userguide/dependency_man ...

  5. vs2008安装opencv2.4.6

    最近安装opencv2.4.6,发现犯了一个很愚蠢的错误,在此记录一下. opencv的头文件包含应该位于build文件夹内,而我误将opencv文件夹下的include包含了进去,造成无法找到头文件 ...

  6. 在mac本上删除mysql

    The steps: First you need to edit the file in: /etc/hostconfig and remove the line Since this is a s ...

  7. 像51一样操作STM32的IO(转)

    源:像51一样操作STM32的IO //-------------------------------------------------------------------------------- ...

  8. 深度残差网(deep residual networks)的训练过程

    这里介绍一种深度残差网(deep residual networks)的训练过程: 1.通过下面的地址下载基于python的训练代码: https://github.com/dnlcrl/deep-r ...

  9. ecshop--标签数组

    $properties  商品属性 array(1) { ["商品属性"]=> array(1) { [178]=> array(2) { ["name&qu ...

  10. cocos2d-x 跨平台usleep方法

    #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) #define usleep(t) Sleep(t) #else #include <unistd.h ...