Codeforces Round #226 (Div. 2)B. Bear and Strings
来源:互联网 发布:淘宝店招设计素材 编辑:程序博客网 时间:2024/05/14 08:15
/*
题意就是要找到包含“bear”的子串,计算出个数,需要注意的地方就是不要计算重复。
*/
1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #define maxn 5005 5 6 char str[maxn]; 7 int pos[maxn]; 8 int main() 9 {10 while(~scanf("%s",str))11 {12 int p = 1;13 memset(pos, 0, sizeof(int));14 int len = (int)strlen(str);15 for(int i = 0;i < len;i++){16 if(str[i] == 'b' && str[i+1] == 'e' && str[i+2] == 'a' && str[i+3] == 'r')17 pos[p++] = i;18 }19 // for(int i = 0;i < p;i++)20 // printf("%d ",pos[i]);21 int ans = 0;22 int num;23 pos[0] = -1;24 for(int i = 1;i < p;i++){25 num = (len - pos[i] - 3)*(pos[i]-pos[i-1]);26 //printf("%d*\n",num);27 ans += num;28 }29 printf("%d\n",ans);30 }31 return 0;32 }
0 0
- Codeforces Round #226 (Div. 2) B. Bear and Strings
- Codeforces Round #226 (Div. 2)B. Bear and Strings
- Codeforces Round #226 (Div. 2)B. Bear and Strings
- Codeforces Round #356 (Div. 2) B Bear and Finding Criminals
- Codeforces Round #179 (Div. 2) B. Yaroslav and Two Strings
- Codeforces Round #226 (Div. 2) A. Bear and Raspberry
- Codeforces Round #226 (Div. 2) C. Bear and Prime Numbers
- Codeforces Round #226 (Div. 2)A. Bear and Raspberry
- Codeforces Round #226 (Div. 2)A. Bear and Raspberry
- Codeforces Round #226 (Div. 2)C. Bear and Prime Numbers
- Codeforces Round #226 (Div. 2) D. Bear and Floodlight
- Codeforces Round #226 (Div. 2)--A Bear and Raspberry
- Codeforces Round #226 (Div. 2)--C. Bear and Prime Numbers
- Codeforces Round #405 Div. 1 B. Bear and Tree Jumps
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) B. Bear and Three Musketeers(STL_暴力)
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)B Bear and Three Musketeers
- Codeforces Round #179 (Div. 2) B (codeforces 296b) Yaroslav and Two Strings
- Codeforces 385B Bear and Strings
- HDU(1536)S-Nim (博弈)
- HDU(1867)A + B for you again (KMP)
- Codeforces Round #106 (Div. 2) 149/E E. Martian Strings
- HDU(4522) 湫湫系列故事——过年回家
- HDU(2955)Robberies (0-1背包)
- Codeforces Round #226 (Div. 2)B. Bear and Strings
- Codeforces Round #226 (Div. 2)A. Bear and Raspberry
- 黑马程序员---高新技术之javabean和泛型
- 泰国法院判决中泰“大米换高铁”项目违宪
- 十步完全理解SQL
- box2d 平移连接器
- 写给新接触linq的同学(二)lamda从零来理解
- 为macbook pro安装内存条
- Android使用UncaughtExceptionHandler捕获全局异常