-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp10152 - ShellSort.cpp
57 lines (41 loc) · 1.08 KB
/
p10152 - ShellSort.cpp
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
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <string.h>
#include <iostream>
#define FLUSH while(getchar() != '\n');
char unsorted[200][100];
char sorted[200][100];
int main(void) {
std::ios_base::sync_with_stdio(false);
int case_num, lines;
scanf("%d", &case_num);
FLUSH
for (int case_idx = 0; case_idx < case_num; case_idx++) {
scanf("%d", &lines);
// io fix
FLUSH
memset(unsorted, 0, sizeof unsorted);
memset(unsorted, 0, sizeof sorted);
// parse lines
for (int i = lines - 1; i >= 0; i--) {
gets(unsorted[i]);
}
for (int i = lines - 1; i >= 0; i--) {
gets(sorted[i]);
}
// compare
int moves = 0;
for (int i = 0, j = 0; i < lines && j < lines; i++) {
if (strcmp(unsorted[i], sorted[j]) != 0) {
moves++;
}
else {
j++;
}
}
for (int i = lines - moves; i < lines; i++) {
printf("%s\n", sorted[i]);
}
printf("\n");
}
return 0;
}