解题思路: 看代码就行 很简单。。
注意事项: 注意 答案可能超过int型,需要long long
参考代码:
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long ll;
typedef pair<int,int> P;
#define pi 3.141592653589793238
int mov[4][2]= {{-1,0},{0,1},{1,0},{0,-1}};
int Alice[1000000];
int Bob[1000000];
int main()
{
freopen("C:/Users/86183/Desktop/input.txt","r",stdin);
//freopen("C:\\Users\\86183\\Desktop\\output.txt","w",stdout);
int k;
string str;
while(cin>>k){
getchar();
int Acnt=0;
int Bcnt=0;
getline(cin,str);
int len=str.length();
for(int i=0;i<len;i++){
if(str[i]=='A'){
if(i==0||!isalpha(str[i-1])){
if(i+5==len||(i+5<len&&!isalpha(str[i+5]))){
if(str[i+1]=='l'&&str[i+2]=='i'&&str[i+3]=='c'&&str[i+4]=='e'){
Alice[Acnt++]=i;
i+=4;
}
}
}
}else if(str[i]=='B'){
if(i==0||!isalpha(str[i-1])){
if(i+3==len||(i+3<len&&!isalpha(str[i+3]))){
if(str[i+1]=='o'&&str[i+2]=='b'){
Bob[Bcnt++]=i;
i+=2;
}
}
}
}
}
ll ans=0;
for(int i=0;i<Acnt;i++){
int start=upper_bound(Bob,Bob+Bcnt,Alice[i]-k-4)-Bob;
int End=upper_bound(Bob,Bob+Bcnt,Alice[i]+4+k+1)-Bob;
if(start<Bcnt&&Bob[start]<=Alice[i]+4+k+1){
ans+=End-start;
}
/*while(start<Bcnt&&Bob[start]<=Alice[i]+4+k+1){
ans++;
start++;
}*/
}
printf("%lld\n",ans);
}
return 0;
}
0.0分
10 人评分
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:600 |
C语言训练-大、小写问题 (C语言代码)浏览:614 |
模拟计算器 (C++代码)浏览:807 |
局部变量作函数返回值的问题浏览:981 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:669 |
2005年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:575 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:776 |
【计算两点间的距离】 (C语言代码)浏览:855 |
ACM俱乐部密码浏览:935 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:307 |