(AtCoder Beginner Contest 375)A - Seats
题目大意
给定一个长度为
N
N
N的字符串
S
S
S
S
S
S 只包含"#“和”."
求 "#.#"子串 的出现次数
思路
签到题 O ( N ) O(N) O(N) 模拟即可
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#define rep(i,x,y) for(ll i=x;i<=y;++i)
#define per(i,x,y) for(ll i=x;i>=y;--i)
using namespace std;
typedef long long ll;
string s;
ll n,ans;
inline ll in()
{
ll res=0,f=1;
char ch;
while((ch=getchar())<'0'||ch>'9')
if(ch=='-') f=-1;
res=res*10+ch-'0';
while((ch=getchar())>='0'&&ch<='9')
res=res*10+ch-'0';
return res*f;
}
inline void put(ll x)
{
if(x<0) putchar('-'),x*=-1;
if(x>9) put(x/10);
putchar(x%10+48);
}
int main()
{
n=in();
cin>>s;
rep(i,1,n-2)
if(s[i]=='.'&&s[i+1]=='#'&&s[i-1]=='#') ++ans;
cout<<ans;
return 0;
}