CodeForces 721A
A. One-dimensional Japanese Crossword
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的更多相关文章
- CodeForces 721A One-dimensional Japanese Crossword (水题)
题意:给定一行字符串,让你输出字符‘B'连续出现的次数. 析:直接扫一下就OK了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024 ...
- 【76.57%】【codeforces 721A】One-dimensional Japanese Crossword
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces水题集合[14/未完待续]
Codeforces Round #371 (Div. 2) A. Meeting of Old Friends |B. Filya and Homework A. Meeting of Old Fr ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- FM收音机 RDS的强大功能
FM收音机 RDS的强大功能 分类: MTK2011-04-26 16:06 14889人阅读 评论(6) 收藏 举报 交通公告体育音乐娱乐教育 前言 随着发展,会有越来越多的电台具有RDS广播功能, ...
- struts2.0 s标签_小小鸟_百度空间
struts2.0 s标签 1. Struts2页面开发中常用标签使用说明 1.1.往action里传值的使用方式: <input name="userName" type= ...
- ZOJ 3941 Kpop Music Party
先把能合并的区间都合并起来. 考虑最裸的贪心策略,从左到右一段一段的取. 但是,这样会有错,错在没有考虑每段区间选取最后一个点. 因为N只有10,所以枚举一下哪些区间最后一个点会被选择,然后按照最裸的 ...
- Memcache第一篇---基础教程
Memcache是什么 Memcache是danga.com的一个项目,最早是为 LiveJournal 服务的,目前全世界不少人使用这个缓存项目来构建自己大负载的网站,来分担数据库的压力. 它可以应 ...
- WKWebKit基础
UIWebView & UIWebViewDelegate 这个两个东西在 WKWebKit 中被重构成 14 个类 3 个协议. WKWebKit Framework Classes WKB ...
- Vue.js起步
Vue.js是一套构建用户界面的 渐进式框架,Vue 采用自底向上增量开发的设计,Vue 的核心库只关注视图层.Vue 完全有能力驱动采用单文件组件和 Vue 生态系统支持的库开发的复杂单页应用. V ...
- new sun.misc.BASE64Encoder()报错找不到jar包
解决方案1(推荐): 只需要在project build path中先移除JRE System Library,再添加库JRE System Library,重新编译后就一切正常了. 解决方案2: W ...
- pyhton字符编码问题--decode和encode方法
1 decode和encode方法 字符串在Python内部的表示是unicode编码,因此,在做编码转换时,通常需要以unicode作为中间编码,即先将其他编码的字符串解码(decode)成uni ...
- leetcode--012 single number I
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA0MAAADGCAIAAACfN8xOAAAZ6UlEQVR4nO3dsZKcurbG8fNOnd1nIv
- eclipse-ee修改字体大小和配置Tomcat服务器
参考博客:http://blog.csdn.net/lpftobetheone/article/details/17783791 一.EclipseEE背景色和字体的修改 1.Eclipse背景颜色修 ...