NKEDIT - Hiệu chỉnh văn bản
Tác giả: happyboy99x
Ngôn ngữ: C++
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[51], p[51], t[51];
int k;
int main() {
scanf("%d%s%s",&k,s,p); int res = 0;
for(bool stop = false; !stop; ) {
stop = true;
for(int l = min(strlen(s), strlen(p)), cont = true; l >= k && cont; --l) {
for(int n = strlen(s), i = 0; i <= n - l; ++i) {
strncpy(t, s+i, l); t[l] = 0;
char * tmp = strstr(p, t);
if(tmp != NULL) {
strcpy(s+i, s+i+l); strcpy(tmp, tmp+l);
cont = stop = false; ++res; break;
}
}
}
}
printf("%d\n%s\n%s\n", res, s, p);
return 0;
}