链接:
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;
}