codeforces721A

来源:互联网 发布:windows ime文件 编辑:程序博客网 时间:2024/04/30 17:49
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 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.

题意:就是给你一个字符串,由W和B组成,然后问你有多少个连续的B的块和每个块里面B的数量。

代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn=500;
int a[maxn];
char s[maxn];
int n;
int main()
{
    while(~scanf("%d",&n))
    {
        scanf("%s",s);
        int cnt=0;
        memset(a,0,sizeof(a));
        for(int i=0;i<strlen(s);i++)
        {
            if(s[i]=='B')
            {
                a[cnt]++;
                if(s[i]!=s[i+1])
                {
                    cnt++;
                }
                else continue;
            }
        }
        printf("%d\n",cnt);
        for(int i=0;i<cnt;i++)
        {
            printf("%d ",a[i]);
        }
        printf("\n");
    }
    return 0;
}














0 0