Today's status is always bad, and this type of question gets stuck for a day...
Is it because the rest time is too short and the mind is too dull...
The name is Hill sorting. I thought it was related to it, and I also searched for information.
If you find trick, you will find it a very watery question. You only need to compare the migrated shells and then output them.
Code:
#include <cstdio> #include <cstring> const int maxn = 1000; char pre[maxn][100], tar[maxn][100]; int main() { int n; // freopen("in", "r", stdin); scanf("%d", &n); while (n--) { int m; scanf("%d", &m); gets(pre[0]); for (int i = m - 1; i >= 0; i--) gets(pre[i]); for (int i = m - 1; i >= 0; i--) gets(tar[i]); int cnt = 0; for (int i = 0, j = 0; i < m;) { if (!strcmp(pre[i], tar[j])) i++, j++; else i++, cnt++; }//for for (int i = m - cnt; i < m; i++) printf("%s\n", tar[i]); printf("\n"); }//while return 0; } #include <cstdio>#include <cstring>const int maxn = 1000;char pre[maxn][100], tar[maxn][100];int main() { int n;// freopen("in", "r", stdin); scanf("%d", &n); while (n--) { int m; scanf("%d", &m); gets(pre[0]); for (int i = m - 1; i >= 0; i--) gets(pre[i]); for (int i = m - 1; i >= 0; i--) gets(tar[i]); int cnt = 0; for (int i = 0, j = 0; i < m;) { if (!strcmp(pre[i], tar[j])) i++, j++; else i++, cnt++; }//for for (int i = m - cnt; i < m; i++) printf("%s\n", tar[i]); printf("\n"); }//while return 0;}