#K90907. Count Watered Plants
Count Watered Plants
Count Watered Plants
You are given a grid of size n × m that represents a field. Each cell in the grid is either a plant that needs watering, represented by the character W
, or an empty cell denoted by .
.
A robot starts at the top-left corner and is supposed to water the plants. In a more complex scenario the robot may only move right or down; however, for this problem the task is simplified: simply count the total number of plants in the grid, i.e., count the occurrences of W
in the grid.
The answer can be formulated as follows:
\[ \text{Answer} = \sum_{i=1}^{n} \sum_{j=1}^{m} \delta(grid[i][j] = 'W') \]
where \(\delta(condition)\) is 1 if the condition is true, and 0 otherwise.
inputFormat
The first line contains two integers n
and m
separated by a space, representing the number of rows and columns of the grid.
The next n
lines each contain a string of length m
, representing the grid. Each character is either W
(indicating a plant that needs watering) or .
(an empty cell).
outputFormat
Output a single integer which is the total number of plants to be watered (i.e., total count of the character W
in the grid).
3 4
W...
.W..
...W
3