Atcoder 280 解题报告
A - Pawn on a Grid
Problem Statement
There is a grid with H rows from top to bottom and W columns from left to right. Each square has a piece placed on it or is empty.
The state of the grid is represented by H strings S1,S 2,…,S H, each of length W.If the j-th character of Si is #, the square at the i-th row from the top and j-th column from the left has a piece on it;if the j-th character of Si is ., the square at the i-th row from the top and j-th column from the left is empty.
How many squares in the grid have pieces on them?
Constraints
1≤H,W≤10
H and W are integers.
Si is a string of length W consisting of # and …
Input
The input is given from Standard Input in the following format:
H W
S1,S2……SH
Output
Print the number of squares with pieces as an integer.
Sample Input 1
Copy
3 5
#…
…
.##…
Sample Output 1
Copy
3
The following three squares have pieces on them:
the square at the 1-st row from the top and 1-st column from the left;
the square at the 3-rd row from the top and 2-nd column from the left;
the square at the 3-rd row from the top and 3-rd column from the left.
Thus, 3 should be printed.
Sample Input 2
Copy
1 10
…
Sample Output 2
Copy
0
Since no square has a piece on it, 0 should be printed.
Sample Input 3
Copy
6 5
#.#.#
…#
…##.
####.
…#…
Sample Output 3
Copy
16
循环统计‘#’的个数即可
#include <bits/stdc++.h>
using namespace std;
int n,w,ans=0;
string s;
int main(){
cin >> n >> w;
for(int i=1;i<=n;++i){
cin >> s;
for(int k=0;k<w;++k)
if(s[k]=='#')
ans++