Codeforces #374(Div.2)A. One-dimensional Japanese Crossword【模拟】水题
来源:互联网 发布:win10怎么安装sql 编辑:程序博客网 时间:2024/05/22 02:09
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 sizeda × 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 Wikipediahttps://en.wikipedia.org/wiki/Japanese_crossword).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting ofn squares (e.g. japanese crossword sized1 × 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 integern (1 ≤ n ≤ 100) — the length of the row. The second line of the input contains a single string consisting ofn 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 integerk — 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.
题目大意:
让你求在长度为N的字符串中,连续的B的区间个数,和每个区间B的个数。思路:
直接模拟即可。
Ac代码:
#include<stdio.h>#include<string.h>using namespace std;char a[10000];int ans[10000];int main(){ int n; while(~scanf("%d",&n)) { scanf("%s",a); int cont=0; int contz=0; for(int i=0;i<n;i++) { if(a[i]=='B') { int flag=0; for(int j=i;j<n;j++) { if(a[j]=='B')cont++; else { flag=1; i=j;break; } } if(flag==0)break; ans[contz++]=cont; cont=0; } } if(cont!=0) { ans[contz++]=cont; } printf("%d\n",contz); if(contz==0)continue; for(int i=0;i<contz;i++) { printf("%d ",ans[i]); } printf("\n"); }}
- Codeforces #374(Div.2)A. One-dimensional Japanese Crossword【模拟】水题
- Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crossword —— 基础题
- CodeForces 721A One-dimensional Japanese Crossword
- Codeforces 721A-One-dimensional Japanese Crossword
- CodeForces 721A One-dimensional Japanese Crossword(第三场)
- Codeforces721 A. One-dimensional Japanese Crossword (水题)
- A. One-dimensional Japanese Crossword
- 【76.57%】【codeforces 721A】One-dimensional Japanese Crossword
- Codeforce 721A One-dimensional Japanese Crossword
- Codeforces Round #Pi (Div. 2)_D. One-Dimensional Battle Ships
- Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships
- Codeforces Round #363 (Div. 2) B. One Bomb(模拟)
- Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships 二分 stl应用
- D. One-Dimensional Battle Ships-二分答案-Codeforces Round #Pi (Div. 2)
- Codeforces Round #Pi (Div. 2)567D One-Dimensional Battle Ships(set)
- Codeforces Round #Pi (Div. 2) —— D One-Dimensional Battle Ships
- Codeforces Round #363(Div. 2) A. Launch of Collider【模拟】 && B. One Bomb【暴力】
- Codeforces Beta Round #74 (Div. 2) / 90B African Crossword (模拟)
- 删除链表重复节点-java
- OpenCV Source
- 渲染世界的OPENGL<15>纹理进阶-点精灵
- python正则表达式 学习记要
- 怎么在 unity 里鼠标旋转一个物体
- Codeforces #374(Div.2)A. One-dimensional Japanese Crossword【模拟】水题
- Sublime text 3 安装pylinter的错误提示
- webstom安装地址及快捷键
- Sublime + Emmet
- JAVA基础再回首(二十六)——面向对象思想设计原则、设计模式、简单工厂模式、工厂方法模式、单例设计模式之饿汉式和懒汉式、Runtime类
- 63.Search in Rotated Sorted Array II-搜索旋转排序数组 II(中等题)
- 如何把安全证书导入到java中的cacerts证书库
- SVMLIB
- windows下Android开发环境部署