日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crosswor 水题

發布時間:2024/4/17 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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; }

轉載于:https://www.cnblogs.com/qscqesze/p/5925873.html

總結

以上是生活随笔為你收集整理的Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crosswor 水题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。