zoukankan      html  css  js  c++  java
  • 【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
    ", k);
        for (int i = 1; i <= k - 1; i++)
            printf("%d ", ans[i]);
        if (k > 0)
            printf("%d
    ", ans[k]);
        return 0;
    }
  • 相关阅读:
    文件可视化的脚本
    Qt error: invalid application of 'sizeof' to incomplete type 'QStaticAssertFailure<false>'
    libusb(4)在Qt中使用libusb
    USB开发者培训(2)架构、系统、协议和供电
    USB开发者培训(1)技术背景
    你的py文件转换成linux可执行程序
    UOS在启动KVM虚拟机时,发生了如下错误
    远程文件到本地
    linux系统后台运行python脚本
    IEEE Journals, Conferences and Their Abbreviation
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7632204.html
Copyright © 2011-2022 走看看