#abc280a. A - Pawn on a Grid
A - Pawn on a Grid
Score : points
问题描述
存在一个网格,从上到下有 行,从左到右有 列。每个格子上都放置了一个棋子或为空。
网格的状态由 个长度为 的字符串 表示。
如果 的第 个字符是 #
,则表示从顶部数第 行、从左边数第 列的格子上有一个棋子;
如果 的第 个字符是 .
, 则表示从顶部数第 行、从左边数第 列的格子为空。
请问网格中有多少个格子上有棋子?
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a grid with rows from top to bottom and columns from left to right. Each square has a piece placed on it or is empty.
The state of the grid is represented by strings , each of length .
If the -th character of is #
, the square at the -th row from the top and -th column from the left has a piece on it;
if the -th character of is .
, the square at the -th row from the top and -th column from the left is empty.
How many squares in the grid have pieces on them?
Constraints
- and are integers.
- is a string of length consisting of
#
and.
.
Input
The input is given from Standard Input in the following format:
Output
Print the number of squares with pieces as an integer.
Sample Input 1
3 5
#....
.....
.##..
Sample Output 1
3
The following three squares have pieces on them:
- the square at the -st row from the top and -st column from the left;
- the square at the -rd row from the top and -nd column from the left;
- the square at the -rd row from the top and -rd column from the left.
Thus, should be printed.
Sample Input 2
1 10
..........
Sample Output 2
0
Since no square has a piece on it, should be printed.
Sample Input 3
6 5
#.#.#
....#
..##.
####.
..#..
#####
Sample Output 3
16
update @ 2024/3/10 11:45:49