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

Copy

3
BBW

output

Copy

1
2 

input

Copy

5
BWBWB

output

Copy

3
1 1 1 

input

Copy

4
WWWW

output

Copy

0

input

Copy

4
BBBB

output

Copy

1
4 

input

Copy

13
WBBBBWWBWBBBW

output

Copy

3
4 1 3 

题意看的一脸懵逼,仔细看了看样例感觉应该是求整个字符串中连续的B的个数,每段输出,居然过了,有时候还要靠猜测题意了。。。

AC 代码:

#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
char c[10005];
int re[10005];
int main()
{int n;cin>>n;memset(re,0,sizeof(re));for(int i=0;i<n;i++){cin>>c[i];}int k=0,sum=0;for(int i=0;i<n;i++){int a=0;if(c[i]=='B'){while(c[i]=='B'){a++;//连续区间内B的个数i++;}sum++;//连续区间的个数re[k++]=a;}}cout<<sum<<endl;if(sum){for(int i=0;i<k;i++){if(i) cout<<" "<<re[i];else cout<<re[i];}cout<<endl;    }} 

【codeforces 721A】One-dimensional Japanese Crossword相关推荐

  1. 【CodeForces - 144C】Anagram Search(尺取,滑窗问题,处理字符串计数)

    题干: A string t is called an anagram of the string s, if it is possible to rearrange letters in t so ...

  2. 【CodeForces - 574B】Bear and Three Musketeers (枚举边,思维,优秀暴力)

    题干: Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Ri ...

  3. 【CodeForces - 608C】Chain Reaction (二分 或 dp ,思维)

    题干: 题目大意: 题意是在一条直线上坐落着不同位置的灯塔,每一个灯塔有自己的power level,当作是射程范围.现在从最右边的灯塔开始激发,如果左边的灯塔在这个灯塔的范围之内,那么将会被毁灭.否 ...

  4. 「一题多解」【CodeForces 85D】Sum of Medians(线段树 / 分块)

    题目链接 [CodeForces 85D]Sum of Medians 题目大意 实现一个setsetset,支持插入,删除,求∑a5k+3∑a5k+3\sum a_{5k+3}.注意,setsets ...

  5. 【CodeForces 997C】Sky Full of Stars(组合计数)

    题目链接:[CodeForces 997C]Sky Full of Stars 官方题解:Codeforces Round #493 - Editorial 题目大意:有一个n×nn×nn\times ...

  6. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

  7. 【codeforces 508B】Anton and currency you all know

    [题目链接]:http://codeforces.com/contest/508/problem/B [题意] 给你一个奇数; 让你交换一次数字; 使得这个数字变成偶数; 要求偶数要最大; [题解] ...

  8. 【codeforces 711B】Chris and Magic Square

    [题目链接]:http://codeforces.com/contest/711/problem/B [题意] 让你在矩阵中一个空白的地方填上一个正数; 使得这个矩阵两个对角线上的和; 每一行的和,每 ...

  9. 【codeforces 807C】Success Rate

    [题目链接]:http://codeforces.com/contest/807/problem/C [题意] 给你4个数字 x y p q 要求让你求最小的非负整数b; 使得 (x+a)/(y+b) ...

最新文章

  1. 老男孩IT教育在线3期新学员司毅的计算机的基础知识
  2. python大一知识点串讲_python-前20天的着重知识点
  3. python项目之古诗文网
  4. python绝对值函数偏码_绝对值python
  5. (10)Zynq IIC控制器介绍
  6. Spring中IOC和AOP的详细解释(转)
  7. c语言超市收银台程序,超市收银电脑操作流程
  8. Traceview命令
  9. UCOS操作系统——系统内部任务(六)
  10. 常用手机屏幕尺寸大小
  11. MFC实现点击按钮打开一个指定的文件或者网址或者exe
  12. android5.0 输入法提取,搜狗手机输入法5.0 Android新版使用体验
  13. NAT 内网穿透原理
  14. linux查看日志内存,linux查看日志、磁盘、cpu、内存使用情况及清理磁盘,日志等。你需要的linux常用基本操作都在这里!!!...
  15. 网站域名https显示证书错误如何解决
  16. 苹果账号总说连接服务器时出错,苹果手机连接iTunes时老是提示 “连接到AppleID服务器时出错”,怎么处理?...
  17. 基于51单片机的硬币电子秤的实现
  18. 北京卓镭激光完成近亿元B轮融资,君联资本领投...
  19. 信息系统项目管理师-项目整合管理
  20. 2022年艺术品和古董投资策略研究报告

热门文章

  1. Linux tail命令的使用方法详解
  2. 50款拥有超赞用户体验的精美移动UI设计
  3. 美颜sdk算法总概——美白
  4. python办公笔记分享
  5. 创翼NetKeeper校园网连接时出现118错误
  6. 5.2 强归纳法和良序性
  7. MySQL大表DDL工具gh-ost
  8. Linux(Ubuntu)下使用OneNote
  9. 2010考研数学二第(11)题——高阶导数
  10. 如何在vmlogin中设置易路代理yiluproxy?