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.
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).
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.
3 BBW
1 2
5 BWBWB
3 1 1 1
4 WWWW
0
4 BBBB
1 4
13 WBBBBWWBWBBBW
3 4 1 3
The last sample case correspond to the picture in the statement.
题意&&思路:
水题,找出连续的 B 块就行了。
CODE:
#include<stdio.h>
#include<cstring>
#include<algorithm>
#define AC main()
using namespace std;
const int MYDD = 1103;
int AC {//国庆节快乐
// while(1) {
int n, ans[MYDD];
char a[MYDD];
scanf("%d", &n);
scanf("%s", a);
for(int j = 0; j < MYDD; j++) ans[j] = 0;
int v = 0;
for(int j = 0; j < n; j++) {
if(a[j] == 'B') {
while(a[j] == 'B') {
ans[v]++;
j++;
}
v++;
}
}
printf("%d\n", v);
for(int j = 0; j < v; j++)
printf("%d ", ans[j]);
// puts("");
// }
return 0;
}

本文介绍了一道关于一维日本填字游戏的编程题目,任务是将一行由黑白方格组成的序列转换为对应的数字线索,以表示连续的黑色方格组。文章提供了完整的解题思路及代码实现。
649

被折叠的 条评论
为什么被折叠?



