/C06018 - Tập từ riêng của hai xâu 2
<Problem>
https://code.ptit.edu.vn/student/question/C06018#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <ctype.h>
void split(char s[], char arr[100][201], int* n) {
int len = 0;
const char* delim = " ";
char* token = strtok(s, delim);
while (token != NULL) {
strcpy(arr[len++], token);
token = strtok(NULL, delim);
}
*n = len;
}
int main() {
int t;
scanf("%d", &t);
getchar();
while (t--) {
char s1[201];
char s2[201];
gets(s1);
gets(s2);
char arr1[100][201];
char arr2[100][201];
char res[100][201];
int n1, n2, n3 = 0;
split(s1, arr1, &n1);
split(s2, arr2, &n2);
for (int i = 0; i < n1; i++) {
bool check = true;
for (int j = 0; j < n2; j++) {
if (strcmp(arr1[i], arr2[j]) == 0) {
check = false;
break;
}
}
if (check) {
bool lastCheck = true;
for (int j = 0; j < n3; j++) {
if (strcmp(arr1[i], res[j]) == 0) {
lastCheck = false;
break;
}
}
if (lastCheck) strcpy(res[n3++], arr1[i]);
}
}
for (int i = 0; i < n3 - 1; i++) {
for (int j = n3 - 1; j > i; j--) {
if (strcmp(res[j], res[j - 1]) < 0) {
char tmp[201];
strcpy(tmp, res[j]);
strcpy(res[j], res[j - 1]);
strcpy(res[j - 1], tmp);
}
}
}
for (int i = 0; i < n3; i++) {
printf("%s ", res[i]);
}
printf("\n");
}
return 0;
}