Count Black Cells
EasyPractice library · +10 XPmatrixtraversalbeginner
You are given an N x M grid filled with characters. Your task is to count the number of cells that contain the character '#'.
Input
The first line contains two integers N and M (1 <= N, M <= 1000). This is followed by N lines, each containing M characters representing a row of the grid. The characters will be either '.' or '#'.
Output
Print a single integer: the total count of '#' characters in the grid.
Constraints
1 <= N, M <= 1000. The grid contains only '.' and '#'.
Time limit 1 s (native code; slower languages get more)Memory 256 MB15 hidden tests
Example 1
Input
3 4 .#.. ##.# ..#.
Output
5
The grid has 4 '#' characters.
Example 2
Input
2 2 .. ..
Output
0
The grid has 0 '#' characters.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
3 4 .#.. ##.# ..#.
Example 2 input
2 2 .. ..