Codeforces Round #226 (Div. 2)B. Bear and Strings
2014-03-14 17:22
337 查看
/* 题意就是要找到包含“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 }
相关文章推荐
- Codeforces Round #195 (Div. 2) D题Vasily the Bear and Beautiful Strings
- Codeforces Round #226 (Div. 2) B. Bear and Strings
- CF 226 DIV2 B. Bear and Strings
- Codeforces Round #226 (Div. 2)B. Bear and Strings
- [Codeforces Round #195 DIV2D (CF336D)] Vasily the Bear and Beautiful Strings
- Codeforces Round #179 (Div. 2) B. Yaroslav and Two Strings(容斥原理)
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) A. Bear and Poker 分解
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) A. Bear and Three Balls 水题
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) C. Bear and Up-Down
- Codeforces Round #358 (Div. 2) Alyona and Strings
- Codeforces Round #358 (Div. 2) D. Alyona and Strings
- Codeforces Round #226 (Div. 2) C. Bear and Prime Numbers(暴力)
- 【VK Cup 2016 - Round 1 (Div 2 Edition)C Bear and Forgotten Tree 3 (构造)
- CodeForces #318 (div1) A.Bear and Poker
- Codeforces Round #226 (Div. 2) D. Bear and Floodlight
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)D Bear and Blocks
- Codeforces Round #356 (Div. 2)-D- Bear and Tower of Cubes
- VK Cup 2016 - Round 1 (Div. 2 Edition) A. Bear and Reverse Radewoosh 水题
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) C. Bear and Drawing
- 【VK Cup 2016 - Round 1 (Div 2 Edition)A】【水题 暴力】Bear and Reverse Radewoosh 做题由易到难分高有难到易分高