Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crosswor 水题
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 水题的更多相关文章
- Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)
Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...
- 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 ...
- 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/ ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Firefox滚动残影(转)
Firefox滚动残影 Firefox滚动残影这文章放在草稿箱有一阵子了,之前的3系列都有这BUG,当正想发表这文章的时候,和我沟通刚刚升级的FF4已修复此BUG,所以搁置一阵在考虑到这文章还有没 ...
- unp学习笔记——Chapter1
1.发现网络拓扑的几个重要的命令 (1).netstat -i 提供网络接口的信息.我们还指定-n 标志以输出数值地址,而不是试图把它们反向解析成名字.netstat -r 展示路由表. dzhwen ...
- MySQL忘记密码了怎么办?
接手一个项目时,如果上一位负责人没有把项目文档.账号密码整理好是一件很头疼的事情.. 例如,当你想打开MySQL数据库的时候 输入: mysql -u root -p 一回车想输入密码,发现密码错误! ...
- Django用ajax进行post请求
post请求有两种,跨域和不跨域 1.不跨域 # 不跨域的 view.py def re_json(request): print(request.POST['name']) p1 = Product ...
- 记一次HashMap面试
记一次HashMap面试 从网上已经身边同事朋友的面试情况来看,面试HashMap几乎是必问的,网上也很多类似的文章,但是真面起来,发现还是有很多点可以深抠的.本篇就结合一次面试经历说一下之前没有注意 ...
- javascript 模拟按键点击提交
上代码 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> & ...
- [Android]Eclipse 安装 ADT[Android Development Tooling] 失败的两种解决办法
原因 最近想在新装的 Win7 里搭建一下 Android 的开发环境,虽然现在有 Android Studio 了,不过还是习惯 Eclipse 一点.众所周知的原因,Eclipse 直接安装 AD ...
- 09 Go 1.9 Release Notes
Go 1.9 Release Notes Introduction to Go 1.9 Changes to the language Ports ppc64x requires POWER8 Fre ...
- TypeError: Object of type 'int64' is not JSON serializable
错误类型:TypeError: Object of type 'int64' is not JSON serializable 错误场景:对Numpy和Pandas结果进行json.dumps报错 错 ...
- 解决C/C++语言中全局变量重复定义的问题
前言 今天,在整理自己的代码的时候,考虑到我写的代码从一至终都是在一个cpp文件里面.于是,想把自己的代码中的各个模块分离开来,以便更好地阅读和管理. 遇到的问题 我的做法是: 宏定义.结构体定义.函 ...