-
Notifications
You must be signed in to change notification settings - Fork 0
/
10152.c
58 lines (58 loc) · 799 Bytes
/
10152.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
47
48
49
50
51
52
53
54
55
56
57
58
#include<stdio.h>
#include<string.h>
char s[1000][2000];
typedef struct
{
char name[2000];
int num;
} shell;
shell md[1000];
shell *m[1000];
void out(int x)
{
int i;shell *temp=m[x];
puts(m[x]->name);
for (i=x;i>0;i--)
m[i]=m[i-1];
m[0]=temp;
}
main()
{
int i,j,k,l,total,row,max;
scanf("%d",&total);
for (l=1;l<=total;l++)
{
scanf("%d",&row);
getchar();
for (j=0;j<row;j++)
{
gets(md[j].name);
m[j]=&md[j];
}
for (j=0;j<row;j++)
{
gets(s[j]);
for (k=0;k<row;k++)
if (!strcmp(m[k]->name,s[j]))
{
m[k]->num=j;
break;
}
}
k=row-1;
for (i=row-1;i>=0;i--)
if (m[i]->num==k)
k--;
for (i=0;i<row;i++)
{
if (k==m[i]->num)
{
out(i);
k--;
i=0;
}
}
putchar('\n');
}
return 0;
}