Atcoder 280 解题报告

本文详细介绍了Atcoder 280比赛中的四个问题:A题通过循环统计字符'#'的数量找出棋盘上有棋子的方格;B题要求找到一个序列,其前缀和等于给定序列,可以通过相邻元素相减得到;C题通过比较两个字符串找到插入的位置;D题寻找最小正整数N,使得N的阶乘能被K整除。
摘要由CSDN通过智能技术生成

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++
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值