解题思路: 看代码就行 很简单。。
注意事项: 注意 答案可能超过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语言程序设计教程(第三版)课后习题6.11 (C语言代码)for循环浏览:1101 |
输出正反三角形 (C语言代码)格式错误!!!浏览:1140 |
C语言训练-求PI* (C语言代码)浏览:613 |
WU-整除问题 (C++代码)浏览:611 |
三角形 (C++代码)记忆化搜索浏览:1220 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:672 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:587 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:1415 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:561 |
字符逆序 (C语言代码)浏览:455 |