There is a grid with $H$ rows from top to bottom and $W$ columns from left to right. Let $(i, j)$ denote the square at the $i$-th row from the top and $j$-th column from the left. For integers $j$ satisfying $1 \leq j \leq W$, let the integer $X_j$ defined as follows. Find all of $X_1, X_2, \dots, X_W$.Problem Statement
The squares are described by characters $C_{i,j}$. If $C_{i,j}$ is .
, $(i, j)$ is empty; if it is #
, $(i, j)$ contains a box.
#
.Constraints
.
or #
.
Input
The input is given from Standard Input in the following format:
$H$ $W$ $C_{1,1}C_{1,2}\dots C_{1,W}$ $C_{2,1}C_{2,2}\dots C_{2,W}$ $\vdots$ $C_{H,1}C_{H,2}\dots C_{H,W}$
Output
Print $X_1, X_2, \dots, X_W$ in the following format:
$X_1$ $X_2$ $\dots$ $X_W$
Sample Input 1
3 4 #..# .#.# .#.#
Sample Output 1
1 2 0 3
In the $1$-st column, one square, $(1, 1)$, contains a box. Thus, $X_1 = 1$.
In the $2$-nd column, two squares, $(2, 2)$ and $(3, 2)$, contain a box. Thus, $X_2 = 2$.
In the $3$-rd column, no squares contain a box. Thus, $X_3 = 0$.
In the $4$-th column, three squares, $(1, 4)$, $(2, 4)$, and $(3, 4)$, contain a box. Thus, $X_4 = 3$.
Therefore, the answer is $(X_1, X_2, X_3, X_4) = (1, 2, 0, 3)$.
Sample Input 2
3 7 ....... ....... .......
Sample Output 2
0 0 0 0 0 0 0
There may be no square that contains a box.
Sample Input 3
8 3 .#. ### .#. .#. .## ..# ##. .##
Sample Output 3
2 7 4
Sample Input 4
5 47 .#..#..#####..#...#..#####..#...#...###...##### .#.#...#.......#.#...#......##..#..#...#..#.... .##....#####....#....#####..#.#.#..#......##### .#.#...#........#....#......#..##..#...#..#.... .#..#..#####....#....#####..#...#...###...#####
Sample Output 4
0 5 1 2 2 0 0 5 3 3 3 3 0 0 1 1 3 1 1 0 0 5 3 3 3 3 0 0 5 1 1 1 5 0 0 3 2 2 2 2 0 0 5 3 3 3 3
按题意模拟去数就行了。
#include<cstdio>
const int N=1005;
int h,w,x[N];
char s[N][N];
int main()
{
scanf("%d%d",&h,&w);
for(int i=1;i<=h;i++)
{
scanf("%s",s[i]+1);
for(int j=1;j<=w;j++)
if(s[i][j]=='#')
++x[j];
}
for(int i=1;i<=w;i++)
printf("%d ",x[i]);
return 0;
}
标签:box,dots,column,Sample,leq,Input,Line,Sensor
From: https://www.cnblogs.com/mekoszc/p/16905398.html