-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_Lab07_1.c
46 lines (35 loc) · 900 Bytes
/
2_Lab07_1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//백준 1764
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_N 100000
int compare(const void *a, const void *b) {
return strcmp(*(const char **)a, *(const char **)b);
}
int main() {
int l, s;
scanf("%d %d", &l, &s);
char *n_heard[MAX_N];
char *n_hs[MAX_N];
for (int i = 0; i < l + s; i++) {
n_heard[i] = (char *)malloc(21);
scanf("%s", n_heard[i]);
}
qsort(n_heard, l + s, sizeof(char *), compare);
int count = 0; // 듣보잡의 수
for (int i = 0; i < l + s - 1; i++) {
if (strcmp(n_heard[i], n_heard[i + 1]) == 0) {
n_hs[count] = n_heard[i];
count++;
i++;
}
}
printf("%d\n", count);
for (int i = 0; i < count; i++) {
printf("%s\n", n_hs[i]);
}
for (int i = 0; i < l + s; i++) {
free(n_heard[i]);
}
return 0;
}