【76.57%】【codeforces 721A】One-dimensional Japanese Crossword
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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
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.
【题解】
要找到连续的黑色块。输出它的总数以及每个连续块的大小;
为什么这种题的通过率不是100%。。。
#include <cstdio>
const int MAXN = 200;
int n, a[MAXN] = { 0 }, ans[MAXN] = { 0 };
char s[MAXN];
int main()
{
//freopen("F:\\rush.txt", "r", stdin);
scanf("%d", &n);
scanf("%s", s);
for (int i = 1; i <= n; i++)
if (s[i - 1] == 'B')
a[i] = 1;
else
a[i] = 0;
int j = 1, k = 0;
while (j <= n)
{
int temp = j;
if (a[temp] == 1)
{
k++;
while (a[temp + 1] == 1)
temp++;
ans[k] = temp - j + 1;
}
j = temp + 1;
}
printf("%d\n", k);
for (int i = 1; i <= k - 1; i++)
printf("%d ", ans[i]);
if (k > 0)
printf("%d\n", ans[k]);
return 0;
}
【76.57%】【codeforces 721A】One-dimensional Japanese Crossword的更多相关文章
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- 【76.83%】【codeforces 554A】Kyoya and Photobooks
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【57.97%】【codeforces Round #380A】Interview with Oleg
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【34.57%】【codeforces 557D】Vitaly and Cycle
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 750C】New Year and Rating(做法2)
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 750A】New Year and Hurry
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 750C】New Year and Rating
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【搜索】【并查集】Codeforces 691D Swaps in Permutation
题目链接: http://codeforces.com/problemset/problem/691/D 题目大意: 给一个1到N的排列,M个操作(1<=N,M<=106),每个操作可以交 ...
随机推荐
- 6lession-基本数据类型
因为自己是根据网上教程学习的,所以以下内容参考自 http://www.w3cschool.cc/python/python-variable-types.html python支持物种数据类型,分别 ...
- softInputMode- 软件盘的设置
今天遇到一个问题,就是软件盘弹出来以后,会把之前的布局界面整个的挤到屏幕的外面,而且按下返回建以后,这个软件盘占据的空间会留下一个黑色的背景.在网上查找了很多的方法,刚开始都是说,如下方法 <a ...
- Encoding encoding = Encoding.GetEncoding("gb2312"); 与byte[] ping = Encoding.UTF8.GetBytes(inputString);区别
Encoding encoding = Encoding.GetEncoding("gb2312"); 与byte[] ping = Encoding.UTF8.GetBytes( ...
- (转)Linux下使用rsync最快速删除海量文件的方法
转自 : http://www.ha97.com/4107.html 昨天遇到了要在Linux下删除海量文件的情况,需要删除数十万个文件.这个是之前的程序写的日志,增长很快,而且没什么用.这个时候,我 ...
- 【hdu 6181】Two Paths
[链接]http://acm.hdu.edu.cn/showproblem.php?pid=6181 [题意] 让你求从1到n的次短路 [题解] 模板题; 因为点可以重复走; 则一定会有次短路. di ...
- 2.1 使用eclipse4.4 搭建 maven简单结构项目。
1.前言 1.本博客面向0基础开发人员. 2.本博客为系列博客.<1.X>系列为服务器数据库相关技术,前几章为简单搭建linux+tomcat+mysql+nginx+redis.< ...
- swiper轮播控件配置项
var mySwiper = new Swiper ('.swiper-container', { direction: 'horizontal', loop: true, auto ...
- 学习笔记:Vue——动态组件&异步组件
动态组件 01.在动态组件上使用keep-alive,保持组件的状态,以避免反复重渲染导致的性能问题. <!-- 失活的组件将会被缓存!--> <keep-alive> < ...
- js进阶 14-3 如何接收load函数从后台接收到的返回数据
js进阶 14-3 如何接收load函数从后台接收到的返回数据 一.总结 一句话总结:load方法的回调函数的参数即可接收从后台的返回数据. 1.load方法的回调函数的参数是什么? 语法:load( ...
- 网络IO
1.前言 在网络编程中,阻塞.非阻塞.同步.异步经常被提到.unix网络编程第一卷第六章专门讨论五种不同的IO模型,Stevens讲的非常详细,我记得去年看第一遍时候,似懂非懂,没有深入理解.网上有详 ...