CodeForces-721A-One-dimensional Japanese Crossword

链接:

https://vjudge.net/problem/CodeForces-721A

题意:

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.Help Adaltik find the numbers encrypting the row he drew.

思路:

模拟算一下,

代码:

#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    int n;
    cin >> n >> s;
    vector<int> res;
    int cnt = 0;
    int tmp = 0, in = 0;
    for (int i = 0;i < s.length();i++)
    {
        if (s[i] == 'B')
        {
            if (in)
                tmp++;
            else
            {
                tmp = 1;
                in = 1;
            }
        }
        else
        {
            if (in)
            {
                res.push_back(tmp);
                in = 0;
                cnt++;
            }
        }
    }
    if (in)
    {
        res.push_back(tmp);
        in = 0;
        cnt++;
    }
    cout << cnt << endl;
    for (int i = 0;i < res.size();i++)
        cout << res[i] << ' ' ;
    cout << endl;

    return 0;
}

转载于:https://www.cnblogs.com/YDDDD/p/11380279.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值