zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    Shell脚本创建Nginx的upstream及location配置文件
    系统初始化
    算法训练 P0505
    算法训练 素因子去重
    基础训练 时间转换
    基础训练 字符串对比
    基础训练 分解质因数
    基础训练 矩形面积交
    快速幂矩阵
    基础训练 矩阵乘法
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11380279.html
Copyright © 2011-2022 走看看