日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Bear and Strings

發布時間:2024/10/5 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Bear and Strings 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

The bear has a string s?=?s1s2… s|s| (record |s| is the string’s length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices i,?j (1?≤?i?≤?j?≤?|s|), that string x(i,?j)?=?sisi?+?1… sj contains at least one string “bear” as a substring.

String x(i,?j) contains string “bear”, if there is such index k (i?≤?k?≤?j?-?3), that sk?=?b, sk?+?1?=?e, sk?+?2?=?a, sk?+?3?=?r.

Help the bear cope with the given problem.

Input
The first line contains a non-empty string s (1?≤?|s|?≤?5000). It is guaranteed that the string only consists of lowercase English letters.

Output
Print a single number — the answer to the problem.

Examples
Input
bearbtear
Output
6
Input
bearaabearc
Output
20
Note
In the first sample, the following pairs (i,?j) match: (1,?4),?(1,?5),?(1,?6),?(1,?7),?(1,?8),?(1,?9).

In the second sample, the following pairs (i,?j) match: (1,??4),?(1,??5),?(1,??6),?(1,??7),?(1,??8),?(1,??9),?(1,??10),?(1,??11),?(2,??10),?(2,??11),?(3,??10),?(3,??11),?(4,??10),?(4,??11),?(5,??10),?(5,??11),?(6,??10),?(6,??11),?(7,??10),?(7,??11).

#include <stdio.h> #include <stdlib.h> #include <string.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */int main(int argc, char *argv[]) {char s[5100];scanf("%s",&s);int i,j;int len=strlen(s);if(len<4)printf("0");else{int count=0;for(i=0;i<len-3;i++){for(j=i;j<len-3;j++){if(s[j]=='b'&&s[j+1]=='e'&&s[j+2]=='a'&&s[j+3]=='r'){ count+=(len-3-j);break;}}}printf("%d\n",count);}return 0; }

總結

以上是生活随笔為你收集整理的Bear and Strings的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。