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 ...
随机推荐
- Linux命令(四)文件传输
1. 将当前目录下的test1.txt文件,复制到 /tmp/Douzi目录下,命名为test1.py 2. 将服务器/tmp/Douzi/hello.py复制到本地上,重命名为 hello_Do ...
- 流媒体服务器之————EasyDarwin开源流媒体服务器:编译、配置、部署
源码下载地址:https://github.com/EasyDarwin/EasyDarwin/archive/v7.0.5.zip 查看 Ubuntu 的版本号 sudo lsb_release - ...
- Brief History of Machine Learning
Brief History of Machine Learning My subjective ML timeline Since the initial standpoint of science, ...
- html5 canvas在线文本第二步设置(字体边框)等我全部写完,我会写在页面底部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- getopts 用法
getopts是linux系统中的一个内置变量,一般用在循环中.每当执行循环是,getopts都会检查下一个命令选项,如果这些选项出现在option中,则表示是合法选项,否则不是合法选项.并将这些合法 ...
- 第5月第24天 线性变换 opengl
1. http://news.qiyeku.com/news_837979.html 2. opengl + (Class)layerClass { return [CAEAGLLayer class ...
- CF293B 方格(带技巧的搜索)
solution: 首先我们根据一条路径上不能有两个相同颜色的格子可以得出: 对于两个格子 \((x_1 , y_1 )\) 和 \((x_2 , y_2 )\) 必须满足: \(x_1<x_2 ...
- mysql区间范围查询问题
一,日期区间查询,表里有一个时间字段 最常见的就是某时间段查询,比如xxxx时间---xxxx时间有多少条数据.例如数据库里的字段是 income_period, 该字段类型可以是字符串(varcha ...
- 【ARTS】01_02_左耳听风-20181119~1125
Algorithm 做一个 leetcode 的算法题 Unique Email Addresses https://leetcode.com/problems/unique-email-addres ...
- 【前端node开发】你需要的Express开发教程
1.极简Node教程-七天从小白变大神(一:你需要Express) https://www.jianshu.com/p/b4701a6efc50