zoukankan      html  css  js  c++  java
  • Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crosswor 水题

    A. One-dimensional Japanese Crossword

    题目连接:

    http://codeforces.com/contest/721/problem/A

    Description

    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.

    Sample Input

    3
    BBW

    Sample Output

    1
    2

    Hint

    题意

    给你一个字符串,问里面有几段B,然后输出每一段B的个数

    题解:

    扫一遍就行了……

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    int n;
    string s;
    int main()
    {
        cin>>n>>s;
        vector<int> ans;
        int tmp = 0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='B')tmp++;
            if(s[i]=='W')
            {
                if(tmp)ans.push_back(tmp);
                tmp=0;
            }
        }
        if(tmp)ans.push_back(tmp);
        cout<<ans.size()<<endl;
        for(int i=0;i<ans.size();i++)
            cout<<ans[i]<<" ";
        cout<<endl;
    }
  • 相关阅读:
    springmvc生成文件(excel、pdf...)和文件上传
    mybatis association 关联查询只返回一条记录
    架构web服务-Nginx07-动静分离
    架构WEB服务-Nginx之六-四层负载均衡
    LVS之三---健康检查
    LVS之2---基于LVS负载均衡集群架构实现
    架构web服务-Nginx之八-nginx实现Rewrite重写
    架构WEB服务-Nginx之五-七层负载均衡
    架构web-Nginx之四-反向代理
    WEB服务-Nginx之三-LNMP架构
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5925873.html
Copyright © 2011-2022 走看看