Pawn on a Grid [AtCoder]

HyunMin Yang·2023년 1월 2일
1
post-thumbnail

Question


Method

1) Get the input of two integers H (height) and W (width)
2) Make a variable for you to count how many numbers of # (squares)
3) Because H (height), is the numbers of lines of input, put it in to a for loop to repeat the process H times
4) Get an input of a line
5) We use the string we have got to act like a list and put it in a for loop. Now, for every i in a string, we can check if it is a "." or a "#"
6) Use the if statement to check if i is a "." or a "#" and if i is "#", we add 1 to the counting variable: cnt
7) The code repeats this process for H times, and after H times, print variable: cnt


Code

H,W = map(int,input().split())
cnt = 0

for _ in range(H):
  string = input()
  for i in string:
    if i == "#":
      cnt +=1

print(cnt)

Results


profile
Hello World!

0개의 댓글