Posted on 2008-09-02 14:33
Hero 阅读(103)
评论(0) 编辑 收藏 引用 所属分类:
代码如诗--ACM
1 //3078 Accepted 320K 0MS G++ 1050B PKU
2
3 //模拟填数
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8
9 char data[50][10] ;
10 int dnum[50] ;
11 int flag[50] ;
12
13 int innum ;
14 int inn, inm ;
15
16 void input()
17 {
18 memset( flag, 0, sizeof(flag) ) ;
19 memset( dnum, 0, sizeof(dnum) ) ;
20
21 scanf( "%d %d", &inn, &inm ) ;
22
23 for( int i=1; i<=inn; i++ )
24 {
25 scanf( "%s", data[i] ) ; //printf( "%s ", data[i] ) ;
26 }
27 }
28
29 void process()
30 {
31 int a, b ;
32 for( int i=1; i<=inm; i++ )
33 {
34 scanf( "%d %d",&a, &b ) ; dnum[b] = a ; flag[a] = 1 ;
35 }
36 int curnum = 1 ;
37 for( int i=1; i<=inn; i++ )
38 {
39 if( 0 == dnum[i] )
40 {
41 while( flag[curnum] ) curnum++ ;
42 dnum[i] = curnum ; flag[curnum] = 1 ;
43 }
44 }
45 }
46
47 void output()
48 {
49 char *blank = "" ;
50 for( int i=1; i<=inn; i++ )
51 {
52 printf( "%s%s", blank, data[dnum[i]] ) ; blank = " " ;
53 }
54 printf( "\n" ) ;
55 }
56
57 int main()
58 {
59 //freopen( "in.txt", "r", stdin ) ;
60
61 while( scanf( "%d", &innum ) != EOF )
62 {
63 for( int ct=1; ct<=innum; ct++ )
64 {
65 input() ;
66
67 process() ;
68
69 output() ;
70 }
71 }
72
73 return 0 ;
74 }