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. elementUI 表格分页后台排序记录

    表格代码 <div class="m-table"> <el-table :data="logs" style="width: 10 ...

  2. Spring Tool Suite 创建 SpringMVC+Maven 项目(一)!

    使用Spring Tool Suite 创建 SpringMVC Web 项目,使用Maven来管理依赖! 首先对环境进行必要的配置 1. 配置必要的Java JDK版本! (菜单栏-窗口-首选项.) ...

  3. 洛谷 P3916 【图的遍历】反向加边+dfs

    前言: 对于这类带环的图,一般记忆化搜索不能很好的对所有遍历的边进行更新取值.因为环上的点可以相互到达,所以他们的答案因当是同步更新的,而dfs一旦你回溯完环上某个点就不会在更新这个点的答案了,做不到 ...

  4. py-faster-rcnn代码阅读2-config.py

    简介  该文件指定了用于fast rcnn训练的默认config选项,不能随意更改,如需更改,应当用yaml再写一个config_file,然后使用cfg_from_file(filename)导入以 ...

  5. git使用常用命令

    第一部分:个人整理部分(读<Git教程By廖雪峰.pdf>笔记) /* 配置全局参数 */git config --global user.name "username" ...

  6. 学习mysql replication gitd

  7. linux系统下安装nginx

    1.第一步:获取nginx的安装包 wget http://nginx.org/download/nginx-1.7.8.tar.gz 2.解压安装包tar -xvf nginx-1.7.8.tar. ...

  8. 基于Apache在本地配置多个虚拟主机站点

    简单的说,打开httpd.conf 在最后加入如下内容: <VirtualHost 127.0.0.2:80>    DocumentRoot d:/AppServ/www2    Ser ...

  9. Ubuntu+Nginx+uWSGI+Flask应用

    Ubuntu 18.04,Nginx 1.14.0,uWSGI 2.0.17.1,Flask 1.0.2,Python 3.6.5, 多日未更新博客,就是在忙着把自己的Flask应用在Ubuntu上运 ...

  10. Linux屏幕记录命令script

    Script -a action.log –t 2> time.log按ctrl+d 退出录制回访 scriptreplay time.log action.log或者直接用查看命令cat,ta ...