简易字符串匹配,题意不难
1 #include2 #include 3 #include 4 #include 5 #include 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 }