Codeforces721 A. One-dimensional Japanese Crosswor

2019-04-15 15:15发布

class="markdown_views prism-github-gist">

Codeforces721 A

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.

题目大意:

统计黑 {MOD}方块个数并计算长度 关键代码,主要这一部分值得记录: 1.if(a[i] == 'B') //B代表黑 {MOD}方块,W代表白 {MOD}方块 2.{ 3. if(i == 0 || s[i-1] == 'W') k++; //k代表黑 {MOD}方块个数 4. a[k]++; //a用来存每块黑 {MOD}段的长度 5.} 本题完整代码: #include #include #include #include #include #include #include typedef long long LL; using namespace std; const int MaxN = 1e5 + 5; char s[105]; int a[105]; int main() { int n; scanf("%d %s", &n, s); int cnt = 0, k = 0; for(int i = 0; i < n; i++) { if(s[i] == 'B') { if(i == 0 || s[i - 1] == 'W') k++; a[k]++; } } printf("%d ", k); for(int i = 1; i <= k; i++) { printf("%d", a[i]); if(i != k) printf(" "); if(i == k) printf(" "); } return 0; }