Codeforces Round #226 (Div. 2)B. Bear and Strings

时间:2023-03-09 02:25:46
Codeforces Round #226 (Div. 2)B. Bear and Strings
 /*
  题意就是要找到包含“bear”的子串,计算出个数,需要注意的地方就是不要计算重复。
*/
1 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define maxn 5005 char str[maxn];
int pos[maxn];
int main()
{
while(~scanf("%s",str))
{
int p = ;
memset(pos, , sizeof(int));
int len = (int)strlen(str);
for(int i = ;i < len;i++){
if(str[i] == 'b' && str[i+] == 'e' && str[i+] == 'a' && str[i+] == 'r')
pos[p++] = i;
}
// for(int i = 0;i < p;i++)
// printf("%d ",pos[i]);
int ans = ;
int num;
pos[] = -;
for(int i = ;i < p;i++){
num = (len - pos[i] - )*(pos[i]-pos[i-]);
//printf("%d*\n",num);
ans += num;
}
printf("%d\n",ans);
}
return ;
}