首页 > 其他 > 详细

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

时间:2014-03-13 07:05:33      阅读:518      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 /*
  题意就是要找到包含“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 }
bubuko.com,布布扣

Codeforces Round #226 (Div. 2)B. Bear and Strings,布布扣,bubuko.com

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

原文:http://www.cnblogs.com/Roly/p/3596281.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!