https://pintia.cn/problem-sets/14/problems/809
so ugly...
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string.h>
using namespace std;
int main() {
char a[100], b[99];
int fl[100];
for (int i = 0; i < 100; i++) {
fl[i] = 1;
}
int cnt = 0;
while (1) {
char c;
scanf("%c", &c);
if (c == '\n') {
a[cnt] = '\0';
break;
}
a[cnt++] = c;
}
cnt = 0;
while (1) {
char c;
scanf("%c", &c);
if (c == '\n') {
b[cnt] = '\0';
break;
}
b[cnt++] = c;
}
//printf("%d ", strlen(b));
bool flag = true;
while (flag) {
flag = false;
for (int i = 0; i < strlen(a); i++) {
int k = i;
int j = 0;
while (j < strlen(b)) {
if (!fl[k + j]) {
k++;
continue;
}
if (a[k + j] == b[j])
j++;
else
break;
}
if (j == strlen(b)) {
flag = true;
j = 0;
k = i;
while (j < strlen(b)) {
if (!fl[k + j]) {
k++;
continue;
}
if (a[k + j] == b[j]) {
fl[k + j] = 0;
j++;
}
else
break;
}
}
}
}
for (int i = 0; i < strlen(a); i++) {
if (fl[i])
printf("%c", a[i]);
}
printf("\n");
return 0;
}
网友评论