1 #include <cstdio>
2 #include <cstring>
3
4 int const max_length = 15;
5 int fflg;
6
7 typedef struct Person Person;
8 struct Person{
9 char name[max_length];
10 int money;
11 int tim;
12 struct Person operator=(struct Person const p){
13 strcpy(name, p.name);
14 money = p.money;
15 tim = p.tim;
16 return *this;
17 }
18 };
19
20 typedef struct Team Team;
21 struct Team{
22 char name[max_length];
23 int cur_player_num;
24 int money;
25 struct Person person[max_length];
26 }team[max_length];
27
28 inline struct Person *find_person(struct Team *t, char *pname, int *pos);
29 inline struct Team *find_team(struct Team *t, int n, char *tname);
30 inline void modify5(struct Team* t, int team_cnt, char *person_name);
31 inline int typefunc(int type, char *team_a, char *team_b, char *person_name, int money, int team_cnt);
32
33 inline struct Person *find_person(struct Team *t, char *pname, int *pos){
34 int i;
35
36 for(i = 0; i < t->cur_player_num; ++i)
37 if(0 == strcmp(t->person[i].name, pname)){
38 *pos = i;
39 return t->person + i;
40 }
41 return NULL;
42 }
43
44 inline struct Team *find_team(struct Team *t, int n, char *tname){
45 int i;
46
47 for(i = 0; i < n; ++i)
48 if(0 == strcmp(t[i].name, tname))
49 return t + i;
50 return NULL;
51 }
52
53 inline void modify5(struct Team* t, int team_cnt, char *person_name){
54 int i, j;
55
56 for(i = 0; i < team_cnt; ++i)
57 for(j = 0; j < t[i].cur_player_num; ++j)
58 if(0 == strcmp(t[i].person[j].name, person_name) && fflg)
59 ;
60 else if(0 < t[i].person[j].tim)
61 t[i].person[j].tim -= 1;
62 }
63
64 inline int typefunc(int type, char *team_a_name, char *team_b_name, char *person_name, int money, int team_cnt){
65 struct Team *pa, *pb;
66 struct Person *pp;
67 int posp = max_length;
68
69 pa = find_team(team, team_cnt, team_a_name);
70 pb = find_team(team, team_cnt, team_b_name);
71 if(1 == type){
72 if(NULL == pb)
73 return 0;
74 pp = find_person(pb, person_name, &posp);
75 if(NULL == pp)
76 return 0;
77 if(0 != pp->tim)
78 return 0;
79 if(pa == pb){
80 pp->money += 100;
81 return 0;
82 }
83 if(NULL == pa)
84 return 0;
85 if(money > pa->money){
86 pp->money += 100;
87 return 0;
88 }
89 if(money < pp->money){
90 pp->money += 100;
91 return 0;
92 }
93 if(pa->cur_player_num > 10){
94 pp->money += 100;
95 return 0;
96 }
97 fflg = 1;
98 pa->person[pa->cur_player_num++] = *pp;//add p to a
99 *pp = pb->person[--pb->cur_player_num];//delete p in b
100 pa->money -= money;
101 pb->money += money;
102 pa->person[pa->cur_player_num - 1].tim = 5;
103 pa->person[pa->cur_player_num - 1].money = money;
104 return 1;
105 } else if(2 == type){
106 if(NULL == pa)
107 return 0;
108 pp = find_person(pa, person_name, &posp);
109 if(NULL == pp)
110 return 0;
111 if(0 != pp->tim)
112 return 0;
113 if(pa == pb){
114 if(pp->money >= 100)
115 pp->money -= 100;
116 return 0;
117 }
118 if(money >= pp->money){
119 if(pp->money >= 100)
120 pp->money -= 100;
121 return 0;
122 }
123 if(NULL == pb)
124 return 0;
125 if(money > pb->money){
126 if(pp->money >= 100)
127 pp->money -= 100;
128 return 0;
129 }
130 if(pb->cur_player_num > 10){
131 if(pp->money >= 100)
132 pp->money -= 100;
133 return 0;
134 }
135 fflg = 1;
136 pb->person[pb->cur_player_num++] = *pp; //add p to b
137 *pp = pa->person[--pa->cur_player_num]; //delete p in a
138 pa->money += money;
139 pb->money -= money;
140 pb->person[pb->cur_player_num - 1].tim = 5;
141 pb->person[pb->cur_player_num - 1].money = money;
142 return 1;
143 }
144 return -1;
145 }
146
147 int main(void){
148 int i, j, t, team_cnt, team_player_num, money, q, type;
149 char team_name[max_length], person_name[max_length];
150 char team_a[max_length], team_b[max_length];
151
152 scanf("%d", &t);
153 while(t--){
154 memset(team, 0, sizeof(team));
155 scanf("%d", &team_cnt);
156 for(i = 0; i < team_cnt; ++i){
157 scanf("%s%d%d", team_name, &team_player_num, &money);
158 strcpy(team[i].name, team_name);
159 team[i].cur_player_num = team_player_num;
160 team[i].money = money;
161 for(j = 0; j < team_player_num; ++j){
162 scanf("%s%d", person_name, &money);
163 strcpy(team[i].person[j].name, person_name);
164 team[i].person[j].money = money;
165 }
166 }
167 scanf("%d", &q);
168 for(i = 0; i < q; ++i){
169 scanf("%d%s%s%s%d", &type, team_a, team_b, person_name, &money);
170 fflg = 0;
171 if(1 == typefunc(type, team_a, team_b, person_name, money, team_cnt)){
172 if(1 == type)
173 printf("%s go to %s from %s for %d.\n", person_name, team_a, team_b, money);
174 else
175 printf("%s go to %s from %s for %d.\n", person_name, team_b, team_a, money);
176 } else
177 puts("No.");
178 modify5(team, team_cnt, person_name);
179 }
180 }
181
182 return 0;
183 }