A. One-dimensional Japanese Crossword

题目连接:

http://codeforces.com/contest/721/problem/A

Description

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.

Sample Input

3

BBW

Sample Output

1

2

Hint

题意

给你一个字符串,问里面有几段B,然后输出每一段B的个数

题解:

扫一遍就行了……

代码

#include<bits/stdc++.h>
using namespace std; int n;
string s;
int main()
{
cin>>n>>s;
vector<int> ans;
int tmp = 0;
for(int i=0;i<s.size();i++)
{
if(s[i]=='B')tmp++;
if(s[i]=='W')
{
if(tmp)ans.push_back(tmp);
tmp=0;
}
}
if(tmp)ans.push_back(tmp);
cout<<ans.size()<<endl;
for(int i=0;i<ans.size();i++)
cout<<ans[i]<<" ";
cout<<endl;
}

Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crosswor 水题的更多相关文章

  1. Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)

    Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...

  2. Codeforces Round #373 (Div. 2) C. Efim and Strange Grade 水题

    C. Efim and Strange Grade 题目连接: http://codeforces.com/contest/719/problem/C Description Efim just re ...

  3. Codeforces Round #185 (Div. 2) A. Whose sentence is it? 水题

    A. Whose sentence is it? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  4. Codeforces Round #373 (Div. 2) A. Vitya in the Countryside 水题

    A. Vitya in the Countryside 题目连接: http://codeforces.com/contest/719/problem/A Description Every summ ...

  5. Codeforces Round #371 (Div. 2) A. Meeting of Old Friends 水题

    A. Meeting of Old Friends 题目连接: http://codeforces.com/contest/714/problem/A Description Today an out ...

  6. Codeforces Round #355 (Div. 2) B. Vanya and Food Processor 水题

    B. Vanya and Food Processor 题目连接: http://www.codeforces.com/contest/677/problem/B Description Vanya ...

  7. Codeforces Round #310 (Div. 2) B. Case of Fake Numbers 水题

    B. Case of Fake Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  8. Codeforces Round #309 (Div. 2) B. Ohana Cleans Up 字符串水题

    B. Ohana Cleans Up Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/554/pr ...

  9. Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks 字符串水题

    A. Kyoya and Photobooks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  10. Codeforces Round #331 (Div. 2) A. Wilbur and Swimming Pool 水题

    A. Wilbur and Swimming Pool Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

随机推荐

  1. Crypto 模块安装

    crypto模块的目的是为了提供通用的加密和哈希算法. AES是一种常用的对称加密算法,加解密都用同一个密钥.crypto模块提供了AES支持,但是需要自己封装好函数,便于使用 方法一: 1,到 ht ...

  2. Ubuntu14.04搭建Android O编译环境

    一.搭建环境 官方参考文档: 1.代号.标签和版本号 2.Factory Images 3.Driver Binaries 4.工具链  软硬件版本: 1.系统平台:I5-8500T+8G+1T,Ub ...

  3. Html设置html与body元素高度问题

    为什么要设置HTML和body的高度? 在一些比较正规的网站经常见到会设置html与body的高度.是为了后面的div高度正确的显示. div的100%是从其上一级div的宽高继承来的,有一点很关键, ...

  4. 公司软raid问题

    RAID的技术介绍: stripe width(条带宽度):RAID中的磁盘数,就是组成这个stripe的磁盘数.如,4个磁盘组成的RAID 0,条带宽度就是4. stripe depth(条带深度) ...

  5. ubuntu 安装(install) pwntcha[一个做"验证码识别"的开源程序]

    一.安装 1. sudo apt-get install libsdl1.2-dev libsdl1.2debian sudo apt-get install libsdl1.2-dev(比较大,10 ...

  6. oracle中使用sql语句生成10w条测试数据

    sql语句 create table AAAATest as select rownum as cardNo, 'test' creator, to_char(sysdate + rownum//, ...

  7. MySql 新建用户与数据库的实际操作步骤

    以下的文章主要讲述的是MySql 新建用户的创建.新建数据库的实际操作步骤以及用户如何进行授权和删除用户的实际操作方案.还有对修改密码的实际操作,以下就是正文的主要内容的创建. 1.MySql 新建用 ...

  8. C++ code:动态内存

    C++给我们提供了动态内存分配的new和delete操作.一般而论,new和delete操作多用在内存需求捉摸不定的场合.然而,需要处理的数据,如果变动范围很小,我们可以用STL中通用型的容器来做,大 ...

  9. InnoDB逻辑存储结构

    从InnoDB存储引擎的逻辑存储结构看,所有数据都被逻辑地存放在一个空间中,称之为表空间(tablespace).表空间又由段(segment).区(extent).页(page)组成.页在一些文档中 ...

  10. CVE-2010-0249 IE8 UAF漏洞分析

    CVE-2010-0249 [CNNVD]Microsoft Internet Explorer非法事件操作内存破坏漏洞(CNNVD-201001-153) Microsoft Internet Ex ...