标签:style class blog code color string
简易字符串匹配,题意不难
1 #include <stdio.h> 2 #include <string.h> 3 #include <math.h> 4 #include <iostream> 5 #include <algorithm> 6 using namespace std; 7 8 int main(){ 9 int i, j, k, t, n; 10 int num, flag, ans; 11 char a[300]; 12 scanf("%s",a); 13 scanf("%d",&k); 14 int len = strlen(a); 15 num = len + k; 16 num /= 2; 17 flag = 0; 18 for(n = num; n > 0; --n){ 19 for(j = 0; j < len; ++j){ 20 i = j; 21 while(i < j + n && i <(len + k - n)){ 22 if((i + n) >= len){ 23 ++i; 24 continue; 25 } 26 if(a[i] == a[i + n]){ 27 ++i; 28 continue; 29 } 30 else break; 31 } 32 33 if(i == j + n){ 34 flag = 1; 35 break; 36 } 37 } 38 if(flag) break; 39 } 40 printf("%d\n",n * 2); 41 return 0; 42 }
Codeforces Round #253 (Div. 2), problem: (B)【字符串匹配】,布布扣,bubuko.com
Codeforces Round #253 (Div. 2), problem: (B)【字符串匹配】
标签:style class blog code color string
原文地址:http://www.cnblogs.com/wushuaiyi/p/3807163.html