完全模拟FIFA2014世界杯 原创求顶!

完全模拟FIFA2014世界杯 原创求顶!

还沉浸在2014世界杯吗? 快用程序模拟属于自己独一无二的世界杯吧!

FIFA2014世界杯模拟器

你值得拥有

// 类 player、 team的定义及实现, 代码放到 player_team.cpp 中

1 #include

2 #include

3 using namespace std;

4 class player {

5 public:

6 player();

7 player(int number, string name, string pos);

8 ~player();

9

10 string get_name();

11 void set_name(string);

12 string get_pos();

13 void set_pos(string);

14 int get_number();

15 void set_number(int);

16 int get_goal();

17 void did_goal(); // 球员进球用

18

19 private:

20 string name;

21 string pos;

22 int goal;

23 int number;

24 };

25

26

27 class team {

28 public:

29 team();

30 team(string continent, string name, int ranking);

31 ~team();

32

33 void set_ranking(int);

34 int get_ranking();

35 void set_name(string);

36 string get_name();

37 void set_continent(string);

38 string get_continent();

39 void set_member(int,player a); // 传入参数是位置0-10

40 player get_member(int); // 传入参数是位置0-10

41 void add_goal(int pos);// pos 为球员位置

42

43 void set_win(int n,int pos);

44 int get_win(int pos);

45 void set_draw(int n,int pos);

46 int get_draw(int pos);

47 void set_lost(int n,int pos);

48 int get_lost(int pos);

49 void set_gf(int n,int pos);

50 int get_gf(int pos);

51 void set_ga(int n,int pos);

52 int get_ga(int pos);

53 void set_gd(int n,int pos);

54 int get_gd(int pos);

55 void set_pts(int n,int pos);

56 int get_pts(int pos);

57

58 private:

59 int ranking;

60 string name;

61 string continent;

62 player member[11];

63

64

65 int win[6]; // 赢

66 int draw[6]; // 平

67 int lost[6]; // 输

68 int gf[6]; // 进球数

69 int ga[6]; // 失球数

70 int gd[6]; // 净胜球数

71 int pts[6]; // 得分

72 };

73

74

75

76

77

78

79 // class player

80 player::player() {

81 goal = 0;

82 }

83

84 player::player(int number, string name, string pos) {

85 this->number = number;

86 this->name = name;

87 this->pos = pos;

88 goal = 0;

89 }

90

91 player::~player() {

92 }

93

94 string player::get_name() {

95 return name;

96 }

97

98 void player::set_name(string name) {

99 this->name = name;

100 }

101

102 string player::get_pos() {

103 return pos;

104 }

105

106 void player::set_pos(string pos) {

107 this->pos = pos;

108 }

109

110 int player::get_number() {

111 return number;

112 }

113

114 void player::set_number(int number) {

115 this->number = number;

116 }

117

118 int player::get_goal() {

119 return goal;

120 }

121

122 void player::did_goal() {

123 goal++;

124 }

125

126

127

128 // class team

129 team::team(){

130 }

131 team::team(string continent, string name, int ranking){

132 this->continent = continent;

133 this->name = name;

134 this->ranking = ranking;

135 for (int i = 0; i < 6;i++) {

136 win[i] = 0;

137 draw[i] = 0;

138 lost[i] = 0;

139 ga[i] = 0;

140 gd[i] = 0;

141 gf[i] = 0;

142 pts[i] = 0;

143 }

144 }

145 team::~team(){

146 }

147

148 void team::set_ranking(int ranking) {

149 this->ranking = ranking;

150 }

151

152 int team::get_ranking() {

153 return ranking;

154 }

155

156 void team::set_name(string name) {

157 this->name = name;

158 }

159

160 string team::get_name() {

161 return name;

162 }

163

164 void team::set_continent(string continent) {

165 this->continent = continent;

166 }

167

168 string team::get_continent() {

169 return continent;

170 }

171

172 void team::set_member(int i ,player p) {// 传入参数是位置0-10

173 this->member[i] = p;

174

175 }

176 player team::get_member(int i) { // 传入参数是位置0-10

177 return this->member[i];

178

179 }

180 void team::add_goal(int pos) {//pos为球员位置

181 this->member[pos].did_goal();

182 }

183 void team::set_win(int i, int pos) {

184 this->win[pos] = i;

185 }

186 int team::get_win(int pos) {

187 return win[pos];

188 }

189

190 void team::set_draw(int i, int pos) {

191 this->draw[pos] = i;

192 }

193 int team::get_draw(int pos) {

194 return draw[pos];

195 }

196

197 void team::set_lost(int i, int pos) {

198 this->lost[pos] = i;

199 }

200 int team::get_lost(int pos) {

201 return lost[pos];

202 }

203

204 void team::set_gf(int i, int pos) {

205 this->gf[pos] = i;

206 }

207 int team::get_gf(int pos) {

208 return gf[pos];

209 }

210

211 void team::set_ga(int i, int pos) {

212 this->ga[pos] = i;

213 }

214 int team::get_ga(int pos) {

215 return ga[pos];

216 }

217

218 void team::set_gd(int i, int pos) {

219 this->gd[pos] = i;

220 }

221 int team::get_gd(int pos) {

222 return gd[pos];

223 }

224

225 void team::set_pts(int i, int pos) {

226 this->pts[pos] = i;

227 }

228 int team::get_pts(int pos) {

229 return pts[pos];

230 }

// 这里的类比较容易就不多讲

// 接下来是main 函数

main函数: 实现了利用4个罐进行A~H组的分档分组抽签、小组赛的日程安排及对战安排、模拟小组赛、各阶段淘汰赛安排及模拟, 直至半决赛、总决赛产生冠亚季军。

整个世界杯流程细节输出到 simulationLog.txt 中, 供随时查看。另各阶段的对战安排、比赛过程、比赛结果输出到相应的txt文件中。

申明:世界杯模拟严格按照FIFA2014官网的规则进行!

1 #include

2 #include

3 #include

4 #include

5 #include

6 #include

7 #include

8 #include "player_team.cpp"

9 using namespace std;

10 fstream log;

11 team competor[32];

12 // compete函数为小组赛竞争函数,允许平局

13 void compete(int stage, team & a, team & b) {

14 // 输出信息

15 cout << endl << "Group Stage:" << endl;

16 cout << a.get_name() << " vs " << b.get_name() << endl;

17 cout << a.get_name() << endl;

18 log << endl << "Group Stage:" << endl;

19 log << a.get_name() << " vs " << b.get_name() << endl;

20 log << a.get_name() << endl;

21 for (int i = 0 ; i < 11; i++) {

22 cout << "#" << a.get_member(i).get_number() << " , " << a.get_member(i).get_name() << " , " << a.get_member(i).get_pos() << endl;

23 log << "#" << a.get_member(i).get_number() << " , " << a.get_member(i).get_name() << " , " << a.get_member(i).get_pos() << endl;

24 }

25 cout << b.get_name() << endl;

26 log << b.get_name() << endl;

27 for (int i = 0 ; i < 11; i++) {

28 cout << "#" << b.get_member(i).get_number() << " , " << b.get_member(i).get_name() << " , " << b.get_member(i).get_pos() << endl;

29 log << "#" << b.get_member(i).get_number() << " , " << b.get_member(i).get_name() << " , " << b.get_member(i).get_pos() << endl;

30 }

31 // 进行比赛

32 cout << "playing..." <

33 log << "playing..." <

34 int a1 = 0,b1 = 0;

35 for (int i = 0; i < 9; i++) {

36 int j = rand() % 3;

37 if (j == 0) {// 0 的话a队进球

38 int tmp = rand() % 11;

39 a.add_goal(tmp);// 某队员进球

40 a.set_gf(a.get_gf(stage) + 1,stage); // a队进球数加 1

41 b.set_ga(a.get_ga(stage) + 1,stage); // b队失球数加 1

42 a1++;

43 cout << a.get_name() << " did a goal, and it was #" << a.get_member(tmp).get_number() << ", " <<

44 a.get_member(tmp).get_name() << " did the goal." <

45 cout << "now it is " << a1 << " : " << b1 << endl;

46 log << a.get_name() << " did a goal, and it was #" << a.get_member(tmp).get_number() << ", " <<

47 a.get_member(tmp).get_name() << " did the goal." <

48 log << "now it is " << a1 << " : " << b1 << endl;

49 } else if (j == 1) {

50 int tmp = rand() % 11;

51 b.add_goal(tmp);// 某队员进球

52 b.set_gf(a.get_gf(stage) + 1,stage); // a队进球数加 1

53 a.set_ga(a.get_ga(stage) + 1,stage); // b队失球数加 1

54 b1++;

55 cout << b.get_name() << " did a goal, and it was #" << b.get_member(tmp).get_number() << ", " <<

56 b.get_member(tmp).get_name() << " did the goal." <

57 cout << "now it is " << a1 << " : " << b1 << endl;

58 log << b.get_name() << " did a goal, and it was #" << b.get_member(tmp).get_number() << ", " <<

59 b.get_member(tmp).get_name() << " did the goal." <

60 log << "now it is " << a1 << " : " << b1 << endl;

61 }

62 }

63 if (a1 > b1) {

64 cout << a.get_name() << " win the game, and it is " << a1 << " : " << b1 << endl;

65 log << a.get_name() << " win the game, and it is " << a1 << " : " << b1 << endl;

66 a.set_win(a.get_win(stage) + 1,stage);

67 b.set_lost(b.get_lost(stage) + 1,stage);

68 } else if (b1 > a1) {

69 cout << b.get_name() << " win the game, and it is " << a1 << " : " << b1 << endl;

70 log << b.get_name() << " win the game, and it is " << a1 << " : " << b1 << endl;

71 b.set_win(b.get_win(stage) + 1,stage);

72 a.set_lost(a.get_lost(stage) + 1,stage);

73 } else {

74 cout << "it is a draw with " << a1 << " : " << b1 << endl;

75 log << "it is a draw with " << a1 << " : " << b1 << endl;

76 a.set_draw(a.get_draw(stage) + 1 ,stage);

77 b.set_draw(b.get_draw(stage) + 1 ,stage);

78 }

79 }

80 // compete_2为淘汰赛的比赛函数,不允许平局

81 int compete_2(team &a, team & b) {

82 // 输出信息

83 cout << endl << "Group Stage:" << endl;

84 cout << a.get_name() << " vs " << b.get_name() << endl;

85 cout << a.get_name() << endl;

86 log << endl << "Group Stage:" << endl;

87 log << a.get_name() << " vs " << b.get_name() << endl;

88 log << a.get_name() << endl;

89 for (int i = 0 ; i < 11; i++) {

90 cout << "#" << a.get_member(i).get_number() << " , " << a.get_member(i).get_name() << " , " << a.get_member(i).get_pos() << endl;

91 log << "#" << a.get_member(i).get_number() << " , " << a.get_member(i).get_name() << " , " << a.get_member(i).get_pos() << endl;

92 }

93 cout << b.get_name() << endl;

94 log << b.get_name() << endl;

95 for (int i = 0 ; i < 11; i++) {

96 cout << "#" << b.get_member(i).get_number() << " , " << b.get_member(i).get_name() << " , " << b.get_member(i).get_pos() << endl;

97 log << "#" << b.get_member(i).get_number() << " , " << b.get_member(i).get_name() << " , " << b.get_member(i).get_pos() << endl;

98 }

99 // 进行比赛

100 cout << "playing..." <

101 log << "playing..." <

102 int a1 = 0,b1 = 0;

103 for (int i = 0; i < 9; i++) {

104 int j = rand() % 3;

105 if (j == 0) {// 0 的话a队进球

106 int tmp = rand() % 11;

107 a.add_goal(tmp);// 某队员进球

108 a.set_gf(a.get_gf(0) + 1,0); // a队进球数加 1

109 b.set_ga(a.get_ga(0) + 1,0); // b队失球数加 1

110 a1++;

111 cout << a.get_name() << " did a goal, and it was #" << a.get_member(tmp).get_number() << ", " <<

112 a.get_member(tmp).get_name() << " did the goal." <

113 cout << "now it is " << a1 << " : " << b1 << endl;

114 log << a.get_name() << " did a goal, and it was #" << a.get_member(tmp).get_number() << ", " <<

115 a.get_member(tmp).get_name() << " did the goal." <

116 log << "now it is " << a1 << " : " << b1 << endl;

117 } else if (j == 1) {

118 int tmp = rand() % 11;

119 b.add_goal(tmp);// 某队员进球

120 b.set_gf(a.get_gf(0) + 1,0); // a队进球数加 1

121 a.set_ga(a.get_ga(0) + 1,0); // b队失球数加 1

122 b1++;

123 cout << b.get_name() << " did a goal, and it was #" << b.get_member(tmp).get_number() << ", " <<

124 b.get_member(tmp).get_name() << " did the goal." <

125 cout << "now it is " << a1 << " : " << b1 << endl;

126 log << b.get_name() << " did a goal, and it was #" << b.get_member(tmp).get_number() << ", " <<

127 b.get_member(tmp).get_name() << " did the goal." <

128 log << "now it is " << a1 << " : " << b1 << endl;

129 }

130 if (i == 8 && a1 == b1) {

131 i = 7;

132 }

133 }

134 if (a1 > b1) {

135 cout << a.get_name() << " win the game, and it is " << a1 << " : " << b1 << endl;

136 log << a.get_name() << " win the game, and it is " << a1 << " : " << b1 << endl;

137 a.set_win(a.get_win(0) + 1,0);

138 b.set_lost(b.get_lost(0) + 1,0);

139 return 1;

140 } else if (b1 > a1) {

141 cout << b.get_name() << " win the game, and it is " << a1 << " : " << b1 << endl;

142 log << b.get_name() << " win the game, and it is " << a1 << " : " << b1 << endl;

143 b.set_win(b.get_win(0) + 1,0);

144 a.set_lost(a.get_lost(0) + 1,0);

145 return 2;

146 } else {

147 cout << "it is a draw with " << a1 << " : " << b1 << endl;

148 log << "it is a draw with " << a1 << " : " << b1 << endl;

149 a.set_draw(a.get_draw(0) + 1 ,0);

150 b.set_draw(b.get_draw(0) + 1 ,0);

151 return 0;

152 }

153 }

154 int main() {

155 srand(time(0));

156 //抽签的话

157 /*************************************************************************************

158 *

159 *以下为抽签阶段开始

160 *

161 *

162 **************************************************************************************/

163 log.open("simulationLog.txt",ios::out);

164 team competor[32];//假设已经从文件输入成功,文件有队名,洲名,排名

165 //从文件输入内容

166 fstream input;

167 input.open("input1.txt");

168 for(int i = 0; i < 32; i++) {

169 string name;

170 string continent;

171 int ranking;

172 input >> name >> continent >> ranking;

173 competor[i].set_name(name);

174 competor[i].set_continent(continent);

175 competor[i].set_ranking(ranking);

176 for (int j = 0; j < 11; j++) {

177 int number;

178 string pos;

179 string name;

180 input >> number >> pos >> name;

181

182 player a(number,name,pos);

183 competor[i].set_member(j, a);

184 }

185 }

186 input.close();

187

188 //输出team32

189 input.open("team32.txt");

190 //AFC

191 int count = 0;

192 for (int i =0 ;i <32 ;i++) {

193 if (competor[i].get_continent() == "AFC") {

194 count++;

195 }

196 }

197 cout << "AFC (" << count << ")" <

198 input << "AFC (" << count << ")" <

199 for (int i =0 ;i <32 ;i++) {

200 if (competor[i].get_continent() == "AFC") {

201 cout << " " << competor[i].get_name() << " (" << competor[i].get_ranking() << ")" << endl;

202 input << " " << competor[i].get_name() << " (" << competor[i].get_ranking() << ")" << endl;

203 }

204 }

205 //CAF

206 count = 0;

207 for (int i =0 ;i <32 ;i++) {

208 if (competor[i].get_continent() == "CAF") {

209 count++;

210 }

211 }

212 cout << "CAF (" << count << ")" <

213 input << "CAF (" << count << ")" <

214 for (int i =0 ;i <32 ;i++) {

215 if (competor[i].get_continent() == "CAF") {

216 cout << " " << competor[i].get_name() << " (" << competor[i].get_ranking() << ")" << endl;

217 input << " " << competor[i].get_name() << " (" << competor[i].get_ranking() << ")" << endl;

218 }

219 }

220 //UEFA

221 count = 0;

222 for (int i =0 ;i <32 ;i++) {

223 if (competor[i].get_continent() == "UEFA") {

224 count++;

225 }

226 }

227 cout << "UEFA (" << count << ")" <

228 input << "UEFA (" << count << ")" <

229 for (int i =0 ;i <32 ;i++) {

230 if (competor[i].get_continent() == "UEFA") {

231 cout << " " << competor[i].get_name() << " (" << competor[i].get_ranking() << ")" << endl;

232 input << " " << competor[i].get_name() << " (" << competor[i].get_ranking() << ")" << endl;

233 }

234 }

235 //CONCACAF

236 count = 0;

237 for (int i =0 ;i <32 ;i++) {

238 if (competor[i].get_continent() == "CONCACAF") {

239 count++;

240 }

241 }

242 cout << "CONCACAF (" << count << ")" <

243 input << "CONCACAF (" << count << ")" <

244 for (int i =0 ;i <32 ;i++) {

245 if (competor[i].get_continent() == "CONCACAF") {

246 cout << " " << competor[i].get_name() << " (" << competor[i].get_ranking() << ")" << endl;

247 input << " " << competor[i].get_name() << " (" << competor[i].get_ranking() << ")" << endl;

248 }

249 }

250 //CONMEBOL

251 count = 0;

252 for (int i =0 ;i <32 ;i++) {

253 if (competor[i].get_continent() == "CONMEBOL") {

254 count++;

255 }

256 }

257 cout << "CONMEBOL (" << count << ")" <

258 input << "CONMEBOL (" << count << ")" <

259 for (int i =0 ;i <32 ;i++) {

260 if (competor[i].get_continent() == "CONMEBOL") {

261 cout << " " << competor[i].get_name() << " (" << competor[i].get_ranking() << ")" << endl;

262 input << " " << competor[i].get_name() << " (" << competor[i].get_ranking() << ")" << endl;

263 }

264 }

265 //

266 int choose[32] = {0};

267 vector pot[4];// 4档

268 vector group[8];

269 // 以下为分档

270 // 冒泡排序

271 for (int i = 1; i <= 30 ; i++) {

272 for (int j = 0; j < 32 - i ; j++) {

273 if (competor[j].get_ranking() > competor[j + 1].get_ranking()) {

274 team tmp;

275 tmp = competor[j];

276 competor[j] = competor[j+1];

277 competor[j+1] = tmp;

278 }

279 }

280 }

281 //循环,将巴西和前7名,放入1档

282 int brazil;

283 for (int i = 0; i <32; i++) {

284 if (competor[i].get_name() == "Brazil(hosts)") {

285 if ( i <= 7 ) {//如果巴西队为前七名

286 brazil = i;

287 break;

288 } else {// 如果不是前七名

289 pot[0].push_back(competor[i]);

290 brazil = i;

291 break;

292 }

293 }

294 }

295 if (brazil <= 7) {

296 for (int i = 0 ;i < 8 ;i++) {

297 pot[0].push_back(competor[i]);

298 choose[i] = 1;

299 }

300 } else {

301 for (int i = 0; i < 7;i++) {

302 pot[0].push_back(competor[i]);

303 choose[i] = 1;

304 }

305 choose[brazil] = 1;

306 }

307 // ,将非洲南美放入2档

308 for (int i = 0; i < 32 ; i++) {

309 if ((competor[i].get_continent() == "CAF" || competor[i].get_continent() == "CONMEBOL") && choose[i] == 0) {

310 pot[1].push_back(competor[i]);

311 choose[i] = 1;

312 }

313 }

314 // ,亚洲,中北美,加勒比放入3档

315 for (int i = 0; i < 32 ; i++) {

316 if ((competor[i].get_continent() == "AFC" || competor[i].get_continent() == "CONCACAF" )

317 && choose[i] == 0) {

318 pot[2].push_back(competor[i]);

319 choose[i] = 1;

320 }

321 }

322 // ,欧洲4档

323 for (int i = 0; i < 32 ; i++) {

324 if ((competor[i].get_continent() == "UEFA") && choose[i] == 0) {

325 pot[3].push_back(competor[i]);

326 choose[i] = 1;

327 }

328 }

329 //显示

330 fstream file;

331 file.open("finalDraw.txt",ios::out);

332 cout << "First Stage:" << endl;

333 file << "First Stage:" << endl;

334 for (int i = 0; i < 4 ; i++) {

335 cout << "pot" << i + 1 << endl;

336 file << "pot" << i + 1 << endl;

337 for (int j = 0; j < pot[i].size(); j++) {

338 cout << " " << pot[i][j].get_name() << endl;

339 file << " " << pot[i][j].get_name() << endl;

340 }

341 }

342

343

344 // 随机抽一个四档的丢入2档

345 int a = rand() % 9;

346 pot[1].push_back(pot[3][a]);

347 vector::iterator it = pot[3].begin();

348 cout << "One European team was first randomly drawn from Pot 4 and "<< endl << "placed into Pot 2: " << (it + a) -> get_name() << endl << endl;

349 file << "One European team was first randomly drawn from Pot 4 and "<< endl << "placed into Pot 2: " << (it + a) -> get_name() << endl << endl;

350 pot[3].erase(it + a);

351

352 cout << "After first draw: "<

353 file << "After first draw: "<

354

355 for (int i = 0; i < 4 ; i++) {

356 cout << "pot" << i + 1 << endl;

357 file << "pot" << i + 1 << endl;

358 for (int j = 0; j < pot[i].size(); j++) {

359 cout << " " << pot[i][j].get_name() << endl;

360 file << " " << pot[i][j].get_name() << endl;

361 }

362 }

363 //以下为分组

364 //fstream debug;

365 //debug.open("debug.txt", ios::out);

366 //将第一档均分为group【0,1,2...】.push_back...

367 for (int i =0; i < 8; i++) {

368 //debug << pot[0][i].get_name() << " ";

369 group[i].push_back(pot[0][i]);

370 }

371 // 随机抽一档中南美队,方法是:产生0-7随机数,检查,将其与被抽入二档的欧洲队一组

372 for (int i =0; i < 8; i++) {

373 //debug << pot[1][i].get_name() << " ";

374 group[i].push_back(pot[1][i]);

375 }

376 // 将二档抽入

377 for (int i =0; i < 8; i++) {

378 //debug << pot[2][i].get_name() << " ";

379 group[i].push_back(pot[2][i]);

380 }

381 //随机分配吧

382 for (int i =0; i < 8; i++) {

383 //debug << pot[3][i].get_name() << " ";

384 group[i].push_back(pot[3][i]);

385 }

386 //debug << endl;

387 for (int i =0 ; i < 8; i++) {

388 for (int j =0;j

389 //debug << group[i][j].get_name() << " ";

390 }

391 //debug << endl;

392 }

393 //debug.close();

394 // 目标 vector group[8];达成。。。。

395 count = 0;

396 for (int i = 0; i < 8; i++ ) {

397 for (int j = 0; j < 4; j++) {

398 competor[count++] = group[i][j];

399 }

400 }

401 // 已经分组了的competor

402 cout << endl;

403 file << endl;

404 cout << "The Final Draw:" <

405 file << "The Final Draw:" <

406 for (int i = 0; i < 8; i++) {

407 char c = 'A';

408 cout << "group " << (char)(c + i) << endl;

409 file << "group " << (char)(c + i) << endl;

410 for (int j = 0; j < 4; j++) {

411 cout << " " << competor[i * 4 + j].get_name() << endl;

412 file << " " << competor[i * 4 + j].get_name() << endl;

413 }

414 }

415 file.close();

416

417 system("pause");

418

419 /*************************************************************************************

420 *以上为抽签阶段结束

421 *以下为第一阶段开始

422 *

423 *

424 **************************************************************************************/

425 pair timetable_32[4][12];

426 for (int i = 0; i < 4; i++) {

427 for (int j = 0; j < 12; j++) {

428 timetable_32[i][j] = make_pair(-1,-1);

429 }

430 }

431 int place_32[4][12] = {0};

432 char* place[12] = {"Estadio Nacionalde Brasilia","Estadio de Morumbi",

433 "Arenade Beira-Rio","Arenada Baixada","Arenade Manaus","Arenadas Dunas",

434 "Estadiode Castelão","EstadioVerdao","Arenada Baixada","FonteNova","Maracana","Mineirao"};

435 // 产生场地安排

436 //随机生成4个不同的0-11的数字,将place【数字】赋给timetable_32里纵排的match的place即可

437 for (int i = 0; i < 12; i++) {

438 int a,b,c,d;

439 a = b = c = d = 0;

440 while(1) {

441 a = rand() % 12;

442 b = rand() % 12;

443 c = rand() % 12;

444 d = rand() % 12;

445 if (a != b && a != c && a != d && b != c && b != d && c != d) {

446 place_32[0][i] = a;

447 place_32[1][i] = b;

448 place_32[2][i] = c;

449 place_32[3][i] = d;

450 break;

451 }

452

453 }

454 }

455 //产生时间表安排

456 //32_比赛表安排

457

458

459 int occupy_32[4][12] = {0};//记录被占用情况

460 for (int i = 0; i < 8; i++) {

461 for (int j = 0; j < 3; j++) {

462 for (int k = j + 1; k < 4; k++) {

463 int flag = 0;

464 while (flag == 0) {

465

466 int a,b;

467

468 a = rand() % 4;

469 b = rand() % 12;

470 if (timetable_32[a][b].first == -1) {

471 int con = 0;

472 for (int l = 0; l < 4 ; l++) {

473 if (timetable_32[l][b].first == (i * 4 + j) || timetable_32[l][b].first == (i * 4 + k) ||

474 timetable_32[l][b].second == (i * 4 + j) || timetable_32[l][b].second == (i * 4 + k)) {

475 con = 1;

476 break;

477 }

478 }

479 if (con != 1) {

480 occupy_32[a][b] = i + 1;

481 timetable_32[a][b] = make_pair(i * 4 + j,i * 4 + k);

482 flag = 1;

483 }

484 }

485 }

486 }

487 }

488 }

489

490

491 file.open("schedule16.txt",ios::out);

492 cout << "Matches by squads" <

493 file << "Matches by squads" <

494 for (int i =0; i < 8; i++) {

495 char c = 'A';

496 cout << "Group " << (char)(c + i) << endl;

497 file << "Group " << (char)(c + i) << endl;

498 for (int j =0 ; j < 4; j++) {

499 for (int k = 0; k < 12 ; k++) {

500 if (occupy_32[j][k] == i + 1) {

501 cout << competor[timetable_32[j][k].first].get_name() << " vs " << competor[timetable_32[j][k].second].get_name();

502 cout << ", " << place[place_32[j][k]] << " , " << "June " << 6 + k <

503 file << competor[timetable_32[j][k].first].get_name() << " vs " << competor[timetable_32[j][k].second].get_name();

504 file << ", " << place[place_32[j][k]] << " , " << "June " << 6 + k <

505 }

506 }

507 }

508 }

509

510 cout << "\nMatches by dates" <

511 file << "\nMatches by dates" <

512 for (int i =0; i < 12 ;i++) {

513 cout << "June " << i + 6 << endl;

514 file << "June " << i + 6 << endl;

515 for (int j = 0; j < 4 ; j++) {

516 cout << competor[timetable_32[j][i].first].get_name() << " vs " << competor[timetable_32[j][i].second].get_name();

517 cout << ", " << place[place_32[j][i]] << endl;

518 file << competor[timetable_32[j][i].first].get_name() << " vs " << competor[timetable_32[j][i].second].get_name();

519 file << ", " << place[place_32[j][i]] << endl;

520 }

521 }

522 file.close();

523

524 system("pause");

525

526 // 按时间进行比赛

527 /*debug段*//*

528 for (int i = 0 ; i < 4; i++) {

529 for (int j = 0; j < 12; j++) {

530 cout << "(" << timetable_32[i][j].first << " , " << timetable_32[i][j].second << ") ";

531 }

532 cout << endl;

533 }

534 */

535 //这一段代码将每个国家的参数初始化为 0 ,需不需要把每个队员的goal初始化为0?

536 for (int k = 0; k < 6 ;k++) {

537 for (int i = 0; i < 8; i++) {

538 for (int j = 0; j < 4; j++) {

539 competor[i * 4 + j].set_win(0,k);

540 competor[i * 4 + j].set_lost(0,k);

541 competor[i * 4 + j].set_draw(0,k);

542 competor[i * 4 + j].set_gf(0,k);

543 competor[i * 4 + j].set_ga(0,k);

544 competor[i * 4 + j].set_gd(0,k);

545 competor[i * 4 + j].set_pts(0,k);

546 }

547 }

548 }

549 /*

550 for (int i = 0; i < 8; i++) {

551 for (int j = 0; j < 4; j++) {

552 cout << competor[i * 4 + j].get_win(1) << " " << competor[i * 4 + j].get_lost(1) << " " <<

553 competor[i * 4 + j].get_draw(1) << " " << competor[i * 4 + j].get_gf(1) << " " <<

554 competor[i * 4 + j].get_ga(1) << " " << competor[i * 4 + j].get_gf(1) << " " << competor[i * 4 + j].get_pts(1) << endl;

555 }

556 }

557 */

558

559 for (int i = 0; i < 12; i++) {

560 cout << endl << "June " << i + 6 << endl << endl;

561 log << endl << "June " << i + 6 << endl << endl;

562 for (int j = 0; j < 4 ; j++) {

563 compete(0, competor[timetable_32[j][i].first], competor[timetable_32[j][i].second]);

564 }

565 }

566 /*debug段

567 for (int i = 0; i < 5; i++) {

568 cout << competor[i].get_name() << endl;

569 for (int j = 0; j < 11; j++) {

570 cout << competor[i].get_member(j).get_number() << " " << competor[i].get_member(j).get_name() <<

571 " " << competor[i].get_member(j).get_pos() << endl;

572 }

573 }*/

574 //第一阶段结束统计

575 for (int i = 0; i < 32; i++) {

576 competor[i].set_gd(competor[i].get_gf(0) - competor[i].get_ga(0),0);

577 competor[i].set_pts(3 * competor[i].get_win(0) + competor[i].get_draw(0),0);

578 }

579 file.open("Result16.txt",ios::out);

580 for (int i = 0; i < 8; i++) {

581 char c = 'A';

582 cout << "Final result for Group " << (char)(c + i) << endl;

583 file << "Final result for Group " << (char)(c + i) << endl;

584 cout << "Team W D L GF GA GD Pts" << endl;

585 file << "Team W D L GF GA GD Pts" << endl;

586 for (int j = 0; j < 4; j++) {

587 cout << left << setw(20) << competor[i * 4 + j].get_name() << " ";

588 cout << left << setw(7) << competor[i * 4 + j].get_win(0) << " ";

589 cout << left << setw(7) << competor[i * 4 + j].get_draw(0) << " ";

590 cout << left << setw(7) << competor[i * 4 + j].get_lost(0) << " ";

591 cout << left << setw(7) << competor[i * 4 + j].get_gf(0) << " ";

592 cout << left << setw(7) << competor[i * 4 + j].get_ga(0) << " ";

593 cout << left << setw(7) << competor[i * 4 + j].get_gd(0) << " ";

594 cout << left << setw(7) << competor[i * 4 + j].get_pts(0) << " ";

595 cout << endl;

596 file << left << setw(20) << competor[i * 4 + j].get_name() << " ";

597 file << left << setw(7) << competor[i * 4 + j].get_win(0) << " ";

598 file << left << setw(7) << competor[i * 4 + j].get_draw(0) << " ";

599 file << left << setw(7) << competor[i * 4 + j].get_lost(0) << " ";

600 file << left << setw(7) << competor[i * 4 + j].get_gf(0) << " ";

601 file << left << setw(7) << competor[i * 4 + j].get_ga(0) << " ";

602 file << left << setw(7) << competor[i * 4 + j].get_gd(0) << " ";

603 file << left << setw(7) << competor[i * 4 + j].get_pts(0) << " ";

604 file << endl;

605 }

606 cout << endl;

607 file << endl;

608 }

609 file.close();

610 //按积分排序

611 for (int i = 0; i < 8; i++) {

612 for (int j = 0 ; j < 4; j++) {

613 int tmp = competor[i * 4 + j].get_pts(0);

614 for (int k = j ; k < 4; k++) {

615 if (competor[i * 4 + k].get_pts(0) > tmp ) {

616 team temp;

617 tmp = competor[i * 4 + k].get_pts(0);

618 temp = competor[i * 4 + k];

619 competor[i * 4 + k] = competor[i * 4 + j];

620 competor[i * 4 + j] = temp;

621

622 }

623 }

624

625 }

626 }

627 // 重排序

628 team tmp[32];

629 count = 0;

630 for (int i = 0; i < 8; i++) {

631 for (int j = 0; j < 2; j++) {

632 tmp[count++] = competor[i * 4 + j];

633 }

634 }

635 for (int i = 0; i < 8; i++) {

636 for (int j = 2; j < 4; j++) {

637 tmp[count++] = competor[i * 4 + j];

638 }

639 }

640 for (int i = 0; i < 32 ;i++) {

641 competor[i] = tmp[i];

642 }

643 //输出

644 file.open("team16.txt",ios::out);

645 cout << "Qualified for round of 16:" << endl;

646 file << "Qualified for round of 16:" << endl;

647 for (int i =0 ;i < 16; i++) {

648 cout << competor[i].get_name() << endl;

649 file << competor[i].get_name() << endl;

650 }

651 file.close();

652 /*************************************************************************************

653 *以上为第一阶段结束

654 *以下为第二阶段开始

655 *

656 *

657 **************************************************************************************/

658 //产生时间安排表

659 int timetable_16[16];

660 for (int i =0 ;i < 16; i++) {

661 timetable_16[i] = -1;

662 }

663 for (int i =0 ;i < 16; i++) {

664 int flag = 0;

665 while (flag == 0) {

666 int k = rand() % 16;

667 if (timetable_16[k] == -1) {

668 timetable_16[k] = i;

669 flag = 1;

670 }

671

672 }

673 }

674 //debug段

675 /*

676 file.open("debug.txt",ios::out);

677 for (int i =0; i< 16; i++) {

678 file << timetable_16[i] << " ";

679 }

680 file.close();

681 */

682 ////////////////////////

683 //以下是显示赛程表

684 file.open("schedule8.txt",ios::out);

685

686 cout << "Matches by dates" <

687 file << "Matches by dates" <

688 for (int i =0; i < 4 ;i++) {

689 cout << "June " << i + 19 << endl;

690 file << "June " << i + 19 << endl;

691 //for (int j = 0; j < 4 ; j++) {

692 int k = rand() % 12, l = rand() % 12;

693 cout << competor[timetable_16[i * 4]].get_name() << " vs " << competor[timetable_16[i * 4 + 1]].get_name();

694 cout << ", " << place[k] << endl;

695 file << competor[timetable_16[i * 4]].get_name() << " vs " << competor[timetable_16[i * 4 + 1]].get_name();

696 file << ", " << place[k] << endl;

697 cout << competor[timetable_16[i * 4 + 2]].get_name() << " vs " << competor[timetable_16[i * 4 + 3]].get_name();

698 cout << ", " << place[l] << endl;

699 file << competor[timetable_16[i * 4 + 2]].get_name() << " vs " << competor[timetable_16[i * 4 + 3]].get_name();

700 file << ", " << place[l] << endl;

701 //}

702 }

703 file.close();

704 //以下是进行比赛并得出结果

705 //首先建立一个临时的存储

706 team tmp_16[32];

707 for (int i = 0; i < 8; i++) {

708 if (i % 2 == 0) {

709 cout << endl << "June " << i / 2 + 19 << endl << endl;//此处有日期输出

710 log << endl << "June " << i / 2 + 19 << endl << endl;

711 }

712 int n = compete_2(competor[timetable_16[i * 2]], competor[timetable_16[i * 2 + 1]]);

713 if (n == 1) {

714 tmp_16[i] = competor[timetable_16[i * 2]];

715 tmp_16[i + 8] = competor[timetable_16[i * 2 + 1]];

716 } else if (n == 2) {

717 tmp_16[i] = competor[timetable_16[i * 2 + 1]];

718 tmp_16[i + 8] = competor[timetable_16[i * 2]];

719 }

720 }

721 for (int i = 0; i < 16; i++) {

722 competor[i] = tmp_16[i];

723 }

724 ///////////////////////////

725 //显示比赛结果和统计信息

726 for (int i = 0; i < 32; i++) {

727 competor[i].set_gd(competor[i].get_gf(0) - competor[i].get_ga(0),0);

728 competor[i].set_pts(3 * competor[i].get_win(0) + competor[i].get_draw(0),0);

729 }

730 file.open("Result8.txt",ios::out);

731 for (int i = 0; i < 1; i++) {

732 char c = 'A';

733 cout << "Final result for round 16" << endl;

734 file << "Final result for round 16" << endl;

735 cout << "Team W D L GF GA GD Pts" << endl;

736 file << "Team W D L GF GA GD Pts" << endl;

737 for (int j = 0; j < 16; j++) {

738 cout << left << setw(20) << competor[i * 4 + j].get_name() << " ";

739 cout << left << setw(7) << competor[i * 4 + j].get_win(0) << " ";

740 cout << left << setw(7) << competor[i * 4 + j].get_draw(0) << " ";

741 cout << left << setw(7) << competor[i * 4 + j].get_lost(0) << " ";

742 cout << left << setw(7) << competor[i * 4 + j].get_gf(0) << " ";

743 cout << left << setw(7) << competor[i * 4 + j].get_ga(0) << " ";

744 cout << left << setw(7) << competor[i * 4 + j].get_gd(0) << " ";

745 cout << left << setw(7) << competor[i * 4 + j].get_pts(0) << " ";

746 cout << endl;

747 file << left << setw(20) << competor[i * 4 + j].get_name() << " ";

748 file << left << setw(7) << competor[i * 4 + j].get_win(0) << " ";

749 file << left << setw(7) << competor[i * 4 + j].get_draw(0) << " ";

750 file << left << setw(7) << competor[i * 4 + j].get_lost(0) << " ";

751 file << left << setw(7) << competor[i * 4 + j].get_gf(0) << " ";

752 file << left << setw(7) << competor[i * 4 + j].get_ga(0) << " ";

753 file << left << setw(7) << competor[i * 4 + j].get_gd(0) << " ";

754 file << left << setw(7) << competor[i * 4 + j].get_pts(0) << " ";

755 file << endl;

756 }

757 cout << endl;

758 file << endl;

759 }

760 file.close();

761 //显示下一阶段的球队

762 file.open("team8.txt",ios::out);

763 cout << "Qualified for round of 8:" << endl;

764 file << "Qualified for round of 8:" << endl;

765 for (int i =0 ;i < 8; i++) {

766 cout << competor[i].get_name() << endl;

767 file << competor[i].get_name() << endl;

768 }

769 file.close();

770 /*************************************************************************

771 *以上为第二阶段

772 *以下为第三阶段

773 *

774 ***************************************************************************/

775 //产生时间安排表

776 int timetable_8[8];

777 for (int i =0 ;i < 8; i++) {

778 timetable_8[i] = -1;

779 }

780 for (int i =0 ;i < 8; i++) {

781 int flag = 0;

782 while (flag == 0) {

783 int k = rand() % 8;

784 if (timetable_8[k] == -1) {

785 timetable_8[k] = i;

786 flag = 1;

787 }

788

789 }

790 }

791 //debug段

792 /*

793 file.open("debug.txt",ios::out);

794 for (int i =0; i< 16; i++) {

795 file << timetable_16[i] << " ";

796 }

797 file.close();

798 */

799 ////////////////////////

800 //以下是显示赛程表

801 file.open("schedule4.txt",ios::out);

802

803 cout << "Matches by dates" <

804 file << "Matches by dates" <

805 for (int i =0; i < 2 ;i++) {

806 cout << "June " << i + 29 << endl;

807 file << "June " << i + 29 << endl;

808 //for (int j = 0; j < 4 ; j++) {

809 int k = rand() % 12, l = rand() % 12;

810 cout << competor[timetable_8[i * 4]].get_name() << " vs " << competor[timetable_8[i * 4 + 1]].get_name();

811 cout << ", " << place[k] << endl;

812 file << competor[timetable_8[i * 4]].get_name() << " vs " << competor[timetable_8[i * 4 + 1]].get_name();

813 file << ", " << place[k] << endl;

814 cout << competor[timetable_8[i * 4 + 2]].get_name() << " vs " << competor[timetable_8[i * 4 + 3]].get_name();

815 cout << ", " << place[l] << endl;

816 file << competor[timetable_8[i * 4 + 2]].get_name() << " vs " << competor[timetable_8[i * 4 + 3]].get_name();

817 file << ", " << place[l] << endl;

818 //}

819 }

820 file.close();

821 //以下是进行比赛并得出结果

822 //首先建立一个临时的存储

823 team tmp_8[32];

824 for (int i = 0; i < 4; i++) {

825 if ( i % 2 ==0) {

826

827 cout << endl << "June " << i/2 + 29 << endl << endl;//此处有日期输出

828 log << endl << "June " << i/2 + 29 << endl << endl;

829 }

830 int n = compete_2(competor[timetable_8[i * 2]], competor[timetable_8[i * 2 + 1]]);

831 if (n == 1) {

832 tmp_8[i] = competor[timetable_8[i * 2]];

833 tmp_8[i + 4] = competor[timetable_8[i * 2 + 1]];

834 } else if (n == 2) {

835 tmp_8[i] = competor[timetable_8[i * 2 + 1]];

836 tmp_8[i + 4] = competor[timetable_8[i * 2]];

837 }

838 }

839 for (int i = 0; i < 8; i++) {

840 competor[i] = tmp_8[i];

841 }

842 ///////////////////////////

843 //显示比赛结果和统计信息

844 for (int i = 0; i < 32; i++) {

845 competor[i].set_gd(competor[i].get_gf(0) - competor[i].get_ga(0),0);

846 competor[i].set_pts(3 * competor[i].get_win(0) + competor[i].get_draw(0),0);

847 }

848 file.open("Result4.txt",ios::out);

849 for (int i = 0; i < 1; i++) {

850 char c = 'A';

851 cout << "Final result for round 8" << endl;

852 file << "Final result for round 8" << endl;

853 cout << "Team W D L GF GA GD Pts" << endl;

854 file << "Team W D L GF GA GD Pts" << endl;

855 for (int j = 0; j < 8; j++) {

856 cout << left << setw(20) << competor[i * 4 + j].get_name() << " ";

857 cout << left << setw(7) << competor[i * 4 + j].get_win(0) << " ";

858 cout << left << setw(7) << competor[i * 4 + j].get_draw(0) << " ";

859 cout << left << setw(7) << competor[i * 4 + j].get_lost(0) << " ";

860 cout << left << setw(7) << competor[i * 4 + j].get_gf(0) << " ";

861 cout << left << setw(7) << competor[i * 4 + j].get_ga(0) << " ";

862 cout << left << setw(7) << competor[i * 4 + j].get_gd(0) << " ";

863 cout << left << setw(7) << competor[i * 4 + j].get_pts(0) << " ";

864 cout << endl;

865 file << left << setw(20) << competor[i * 4 + j].get_name() << " ";

866 file << left << setw(7) << competor[i * 4 + j].get_win(0) << " ";

867 file << left << setw(7) << competor[i * 4 + j].get_draw(0) << " ";

868 file << left << setw(7) << competor[i * 4 + j].get_lost(0) << " ";

869 file << left << setw(7) << competor[i * 4 + j].get_gf(0) << " ";

870 file << left << setw(7) << competor[i * 4 + j].get_ga(0) << " ";

871 file << left << setw(7) << competor[i * 4 + j].get_gd(0) << " ";

872 file << left << setw(7) << competor[i * 4 + j].get_pts(0) << " ";

873 file << endl;

874 }

875 cout << endl;

876 file << endl;

877 }

878 file.close();

879 //显示下一阶段的球队

880 file.open("team4.txt",ios::out);

881 cout << "Qualified for round of 4:" << endl;

882 file << "Qualified for round of 4:" << endl;

883 for (int i =0 ;i < 4; i++) {

884 cout << competor[i].get_name() << endl;

885 file << competor[i].get_name() << endl;

886 }

887 file.close();

888 /*************************************************************************

889 *以上为第三阶段

890 *以下为第四阶段

891 *

892 ***************************************************************************/

893 //产生时间安排表

894 int timetable_4[4];

895 for (int i =0 ;i < 4; i++) {

896 timetable_4[i] = -1;

897 }

898 for (int i =0 ;i < 4; i++) {

899 int flag = 0;

900 while (flag == 0) {

901 int k = rand() % 4;

902 if (timetable_4[k] == -1) {

903 timetable_4[k] = i;

904 flag = 1;

905 }

906

907 }

908 }

909 //debug段

910 /*

911 file.open("debug.txt",ios::out);

912 for (int i =0; i< 16; i++) {

913 file << timetable_16[i] << " ";

914 }

915 file.close();

916 */

917 ////////////////////////

918 //以下是显示赛程表

919 file.open("schedule2.txt",ios::out);

920

921 cout << "Matches by dates" <

922 file << "Matches by dates" <

923 for (int i =0; i < 2 ;i++) {

924 cout << "July " << i + 4 << endl;

925 file << "July " << i + 4 << endl;

926 //for (int j = 0; j < 4 ; j++) {

927 int k = rand() % 12, l = rand() % 12;

928 cout << competor[timetable_4[i * 2]].get_name() << " vs " << competor[timetable_4[i * 2 + 1]].get_name();

929 cout << ", " << place[k] << endl;

930 file << competor[timetable_4[i * 2]].get_name() << " vs " << competor[timetable_4[i * 2 + 1]].get_name();

931 file << ", " << place[k] << endl;

932 //}

933 }

934 file.close();

935 //以下是进行比赛并得出结果

936 //首先建立一个临时的存储

937 team tmp_4[32];

938 for (int i = 0; i < 2; i++) {

939

940 cout << endl << "July " << i + 4 << endl << endl;//此处有日期输出

941 log << endl << "July " << i + 4 << endl << endl;

942

943 int n = compete_2(competor[timetable_4[i * 2]], competor[timetable_4[i * 2 + 1]]);

944 if (n == 1) {

945 tmp_4[i] = competor[timetable_4[i * 2]];

946 tmp_4[i + 2] = competor[timetable_4[i * 2 + 1]];

947 } else if (n == 2) {

948 tmp_4[i] = competor[timetable_4[i * 2 + 1]];

949 tmp_4[i + 2] = competor[timetable_4[i * 2]];

950 }

951 }

952 for (int i = 0; i < 4; i++) {

953 competor[i] = tmp_4[i];

954 }

955 ///////////////////////////

956 //显示比赛结果和统计信息

957 for (int i = 0; i < 32; i++) {

958 competor[i].set_gd(competor[i].get_gf(0) - competor[i].get_ga(0),0);

959 competor[i].set_pts(3 * competor[i].get_win(0) + competor[i].get_draw(0),0);

960 }

961 file.open("Result2.txt",ios::out);

962 for (int i = 0; i < 1; i++) {

963 char c = 'A';

964 cout << "Final result for round 4" << endl;

965 file << "Final result for round 4" << endl;

966 cout << "Team W D L GF GA GD Pts" << endl;

967 file << "Team W D L GF GA GD Pts" << endl;

968 for (int j = 0; j < 4; j++) {

969 cout << left << setw(20) << competor[i * 4 + j].get_name() << " ";

970 cout << left << setw(7) << competor[i * 4 + j].get_win(0) << " ";

971 cout << left << setw(7) << competor[i * 4 + j].get_draw(0) << " ";

972 cout << left << setw(7) << competor[i * 4 + j].get_lost(0) << " ";

973 cout << left << setw(7) << competor[i * 4 + j].get_gf(0) << " ";

974 cout << left << setw(7) << competor[i * 4 + j].get_ga(0) << " ";

975 cout << left << setw(7) << competor[i * 4 + j].get_gd(0) << " ";

976 cout << left << setw(7) << competor[i * 4 + j].get_pts(0) << " ";

977 cout << endl;

978 file << left << setw(20) << competor[i * 4 + j].get_name() << " ";

979 file << left << setw(7) << competor[i * 4 + j].get_win(0) << " ";

980 file << left << setw(7) << competor[i * 4 + j].get_draw(0) << " ";

981 file << left << setw(7) << competor[i * 4 + j].get_lost(0) << " ";

982 file << left << setw(7) << competor[i * 4 + j].get_gf(0) << " ";

983 file << left << setw(7) << competor[i * 4 + j].get_ga(0) << " ";

984 file << left << setw(7) << competor[i * 4 + j].get_gd(0) << " ";

985 file << left << setw(7) << competor[i * 4 + j].get_pts(0) << " ";

986 file << endl;

987 }

988 cout << endl;

989 file << endl;

990 }

991 file.close();

992 //显示下一阶段的球队

993 file.open("team2.txt",ios::out);

994 cout << "They fight for the champion:" << endl;

995 file << "They fight for the champion:" << endl;

996 for (int i =0 ;i < 2; i++) {

997 cout << competor[i].get_name() << endl;

998 file << competor[i].get_name() << endl;

999 }

1000 cout << "They fight for bronze:" << endl;

1001 file << "They fight for bronze:" << endl;

1002 for (int i =2 ;i < 4; i++) {

1003 cout << competor[i].get_name() << endl;

1004 file << competor[i].get_name() << endl;

1005 }

1006 file.close();

1007 /*************************************************************************

1008 *以上为第四阶段

1009 *以下为第五阶段

1010 *

1011 ***************************************************************************/

1012 //产生时间安排表

1013 /*

1014 int timetable_2[2];

1015 for (int i =0 ;i < 2; i++) {

1016 timetable_2[i] = -1;

1017 }

1018 for (int i =0 ;i < 2; i++) {

1019 int flag = 0;

1020 while (flag == 0) {

1021 int k = rand() % 2;

1022 if (timetable_2[k] == -1) {

1023 timetable_2[k] = i;

1024 flag = 1;

1025 }

1026

1027 }

1028 }*/

1029 //debug段

1030 /*

1031 file.open("debug.txt",ios::out);

1032 for (int i =0; i< 16; i++) {

1033 file << timetable_16[i] << " ";

1034 }

1035 file.close();

1036 */

1037 ////////////////////////

1038 //以下是显示赛程表

1039

1040 file.open("schedule1.txt",ios::out);

1041

1042 cout << "Matches by dates" <

1043 file << "Matches by dates" <

1044 count = 0;

1045 for (int i = 1; i >= 0 ;i--) {

1046 cout << "July " << count + 10 << endl;

1047 file << "July " << count + 10 << endl;

1048 count++;

1049 //for (int j = 0; j < 4 ; j++) {

1050 int k = rand() % 12, l = rand() % 12;

1051 cout << competor[i * 2].get_name() << " vs " << competor[i * 2 + 1].get_name();

1052 cout << ", " << place[k] << endl;

1053 file << competor[i * 2].get_name() << " vs " << competor[i * 2 + 1].get_name();

1054 file << ", " << place[k] << endl;

1055 //}

1056 }

1057 file.close();

1058 //以下是进行比赛并得出结果

1059 //首先建立一个临时的存储

1060

1061 team tmp_2[32];

1062 count = 0;

1063 for (int i = 1; i >= 0; i--) {

1064

1065 cout << endl << "July " << count + 10 << endl << endl;//此处有日期输出

1066 log << endl << "July " << count + 10 << endl << endl;

1067 count++;

1068 int n = compete_2(competor[i * 2], competor[i * 2 + 1]);

1069 if (n == 1) {

1070 tmp_2[i] = competor[i * 2];

1071 tmp_2[i + 2] = competor[i * 2 + 1];

1072 } else if (n == 2) {

1073 tmp_2[i] = competor[i * 2 + 1];

1074 tmp_2[i + 2] = competor[i * 2];

1075 }

1076 }

1077 for (int i = 0; i < 4; i++) {

1078 competor[i] = tmp_2[i];

1079 }

1080 ///////////////////////////

1081 //显示比赛结果和统计信息

1082 for (int i = 0; i < 32; i++) {

1083 competor[i].set_gd(competor[i].get_gf(0) - competor[i].get_ga(0),0);

1084 competor[i].set_pts(3 * competor[i].get_win(0) + competor[i].get_draw(0),0);

1085 }

1086 file.open("Result1.txt",ios::out);

1087 for (int i = 0; i < 1; i++) {

1088 char c = 'A';

1089 cout << "Final result for round 2" << endl;

1090 file << "Final result for round 2" << endl;

1091 cout << "Team W D L GF GA GD Pts" << endl;

1092 file << "Team W D L GF GA GD Pts" << endl;

1093 for (int j = 0; j < 4; j++) {

1094 cout << j + 1<< ". ";

1095 file << j + 1<< ". ";

1096 cout << left << setw(17) << competor[i * 4 + j].get_name() << " ";

1097 cout << left << setw(7) << competor[i * 4 + j].get_win(0) << " ";

1098 cout << left << setw(7) << competor[i * 4 + j].get_draw(0) << " ";

1099 cout << left << setw(7) << competor[i * 4 + j].get_lost(0) << " ";

1100 cout << left << setw(7) << competor[i * 4 + j].get_gf(0) << " ";

1101 cout << left << setw(7) << competor[i * 4 + j].get_ga(0) << " ";

1102 cout << left << setw(7) << competor[i * 4 + j].get_gd(0) << " ";

1103 cout << left << setw(7) << competor[i * 4 + j].get_pts(0) << " ";

1104 cout << endl;

1105 file << left << setw(17) << competor[i * 4 + j].get_name() << " ";

1106 file << left << setw(7) << competor[i * 4 + j].get_win(0) << " ";

1107 file << left << setw(7) << competor[i * 4 + j].get_draw(0) << " ";

1108 file << left << setw(7) << competor[i * 4 + j].get_lost(0) << " ";

1109 file << left << setw(7) << competor[i * 4 + j].get_gf(0) << " ";

1110 file << left << setw(7) << competor[i * 4 + j].get_ga(0) << " ";

1111 file << left << setw(7) << competor[i * 4 + j].get_gd(0) << " ";

1112 file << left << setw(7) << competor[i * 4 + j].get_pts(0) << " ";

1113 file << endl;

1114 }

1115 cout << endl;

1116 file << endl;

1117 }

1118 file.close();

1119 //显示下一阶段的球队

1120 file.open("team1.txt",ios::out);

1121 cout << "The champion is:" << endl;

1122 file << "The champion is:" << endl;

1123 for (int i =0 ;i < 1; i++) {

1124 cout << competor[i].get_name() << endl;

1125 file << competor[i].get_name() << endl;

1126 }

1127 file.close();

1128

1129 system("pause");

1130

1131 /*************************************************************************

1132 *以上为第五阶段

1133 *全场比赛结束,进行统计

1134 *

1135 ***************************************************************************/

1136 //top 10 teams

1137 file.open("finalStatics.txt",ios::out);

1138 cout << endl << "Top ten teams:" << endl;

1139 file << endl << "Top ten teams:" << endl;

1140 for (int i = 0; i < 1; i++) {

1141 cout << "Team W D L GF GA GD Pts" << endl;

1142 file << "Team W D L GF GA GD Pts" << endl;

1143 for (int j = 0; j < 10; j++) {

1144 cout << j + 1<< ". ";

1145 file << j + 1<< ". ";

1146 cout << left << setw(17) << competor[i * 4 + j].get_name() << " ";

1147 cout << left << setw(7) << competor[i * 4 + j].get_win(0) << " ";

1148 cout << left << setw(7) << competor[i * 4 + j].get_draw(0) << " ";

1149 cout << left << setw(7) << competor[i * 4 + j].get_lost(0) << " ";

1150 cout << left << setw(7) << competor[i * 4 + j].get_gf(0) << " ";

1151 cout << left << setw(7) << competor[i * 4 + j].get_ga(0) << " ";

1152 cout << left << setw(7) << competor[i * 4 + j].get_gd(0) << " ";

1153 cout << left << setw(7) << competor[i * 4 + j].get_pts(0) << " ";

1154 cout << endl;

1155 file << left << setw(17) << competor[i * 4 + j].get_name() << " ";

1156 file << left << setw(7) << competor[i * 4 + j].get_win(0) << " ";

1157 file << left << setw(7) << competor[i * 4 + j].get_draw(0) << " ";

1158 file << left << setw(7) << competor[i * 4 + j].get_lost(0) << " ";

1159 file << left << setw(7) << competor[i * 4 + j].get_gf(0) << " ";

1160 file << left << setw(7) << competor[i * 4 + j].get_ga(0) << " ";

1161 file << left << setw(7) << competor[i * 4 + j].get_gd(0) << " ";

1162 file << left << setw(7) << competor[i * 4 + j].get_pts(0) << " ";

1163 file << endl;

1164 }

1165 cout << endl;

1166 file << endl;

1167 }

1168

1169 system("pause");

1170

1171 // 射手榜

1172 int table[32][11];//储存每个球员进球数

1173 for (int i = 0; i < 32; i++) {

1174 for (int j = 0; j < 11; j++) {

1175 table[i][j] = competor[i].get_member(j).get_goal();

1176 //cout << competor[i].get_member(j).get_goal();

1177 }

1178 //cout <

1179 }

1180 int tmpp[352];//将刚才的表线性化

1181 count = 0;

1182 for (int i = 0; i < 32; i++) {

1183 for (int j = 0; j < 11; j++) {

1184 tmpp[count++] = table[i][j];

1185 }

1186 }

1187 // 将线性表排序

1188 for (int i = 1; i < 352; i++) {

1189 for (int j = 0; j < 352 - i; j++) {

1190 if (tmpp[j] < tmpp[j + 1]) {

1191 int temp;

1192 temp = tmpp[j];

1193 tmpp[j] = tmpp[j+1];

1194 tmpp[j+1] = temp;

1195 }

1196 }

1197 }

1198 /*

1199 for (int i = 0; i < 352; i++) {

1200 if ((i + 1) % 11 ==0) cout << endl;

1201 cout << tmpp[i] << " " ;

1202 }*/

1203 //输出射手榜

1204 cout << "Top 10 Goalscorers:" << endl;

1205 file << "Top 10 Goalscorers:" << endl;

1206 for (int i =0; i < 10; i++) {

1207 for (int j =0; j < 32; j++) {

1208 for (int k =0; k < 11; k++) {

1209

1210 if (tmpp[i] == table[j][k]) {

1211 cout << table[j][k] << " Goals " << competor[j].get_member(k).get_name() << " " <<

1212 competor[j].get_member(k).get_pos() << " " << competor[j].get_name() << endl;

1213 file << table[j][k] << " Goals " << competor[j].get_member(k).get_name() << " " <<

1214 competor[j].get_member(k).get_pos() << " " << competor[j].get_name() << endl;

1215 tmpp[i] = -1;

1216 table[j][k] = -2;

1217 }

1218 }

1219 }

1220 }

1221

1222 file.close();

1223 log.close();

1224 return 0;

1225 }

// 这里提供32支球队及其球员信息, 放到 input1.txt 中 (球员信息也可更改 )

Australia AFC 62

1 GK Mathew-Ryan

2 DF Ivan-Franjic

3 DF Jason-Davidson

4 FW Tim-Cahill

5 MF Mark-Milligan

6 DF Matthew-?piranovi?

7 FW Mathew-Leckie

8 DF Bailey-Wright

9 FW Adam-Taggart

10 MF Ben-Halloran

11 MF Tommy-Oar

Iran AFC 43

1 GK Rahman-Ahmadi

2 MF Khosro-Heydari

3 MF Ehsa-Hajsafi

4 DF Jalal-Hosseini

5 DF Amir-Hossein-Sadeghi

6 MF Javad-Nekounam

7 MF Masoud-Shojaei

8 MF Reza-Haghighi

9 FW Alireza-Jahanbakhsh

10 FW Karim-Ansarifard

11 MF Ghasem-Haddadifar

Japan AFC 46

1 GK Eiji-Kawashima

2 DF Atsuto-Uchida

3 DF Gotoku-Sakai

4 MF Keisuke-Honda

5 DF Yuto-Nagatomo

6 DF Masato-Morishige

7 MF Yasuhito-Endo

8 MF Hiroshi-Kiyotake

9 FW Shinji-Okazaki

10 MF Shinji-Kagawa

11 FW Yoichiro-Kakitani

South_Korea AFC 57

1 GK Jung-Sung-ryong

2 DF Kim-Chang-soo

3 DF Yun-Suk-young

4 DF Kwak-Tae-hwi

5 DF Kim-Young-gwon

6 DF Hwang-Seok-ho

7 MF Kim-Bo-kyung

8 MF Ha-Dae-sung

9 FW Son-Heung-min

10 FW Park-Chu-young

11 FW Lee-Keun-ho

Algeria CAF 22

1 GK Cedric-Si-Mohamed

2 DF Madjid-Bougherra

3 DF Faouzi-Ghoulam

4 DF Essa?d-Belkalem

5 DF Rafik-Halliche

6 DF Djamel-Mesbah

7 MF Hassan-Yebda

8 MF Medhi-Lacen

9 MF Sofiane-Feghouli

10 MF Yacine-Brahimi

11 DF Carl-Medjani

Cameroon CAF 56

1 GK Lo?c-Feudjou

2 DF Beno?t-Assou-Ekotto

3 DF Nicolas-N'Koulou

4 DF Cedric-Djeugoue

5 DF Dany-Nounkeu

6 MF Alex-Song

7 MF Landry-N'Guemo

8 FW Benjamin-Moukandjo

9 FW Samuel-Eto'o

10 FW Vincent-Aboubakar

11 MF Jean-Makoun

Ghana CAF 37

1 GK Stephen-Adams

2 DF Samuel-Inkoom

3 FW Asamoah-Gyan

4 DF Daniel-Opare

5 MF Michael-Essien

6 MF Afriyie-Acquah

7 MF Christian-Atsu

8 MF Emmanuel-Agyemang-Badu

9 FW Kevin-Prince-Boateng

10 MF Andre-Ayew

11 MF Sulley-Muntari

Ivory_Coast CAF 23

1 GK Boubacar-Barry

2 DF Ousmane-Viera

3 DF Arthur-Boka

4 DF Kolo-Toure

5 DF Didier-Zokora

6 FW Mathis-Bolly

7 DF Jean-Daniel-Akpa-Akpro

8 FW Salomon-Kalou

9 MF Cheick-Tiote

10 FW Gervinho

11 FW Didier-Drogba

Nigeria CAF 44

1 GK Vincent-Enyeama

2 DF Joseph-Yobo

3 MF Ejike-Uzoenyi

4 MF Reuben-Gabriel

5 DF Efe-Ambrose

6 DF Azubuike-Egwuekwe

7 FW Ahmed-Musa

8 FW Peter-Odemwingie

9 FW Emmanuel-Emenike

10 MF John-Obi-Mikel

11 MF Victor-Moses

Costa_Rica CONCACAF 28

1 GK Keylor-Navas

2 DF Johnny-Acosta

3 DF Giancarlo-Gonzalez

4 DF Michael-Uma?a

5 MF Celso-Borges

6 DF oscar-Duarte

7 MF Christian-Bola?os

8 DF David-Myrie

9 FW Joel-Campbell

10 FW Bryan-Ruiz

11 MF Michael-Barrantes

Honduras CONCACAF 33

1 GK Luis-Lopez

2 DF Osman-Chavez

3 DF Maynor-Figueroa

4 DF Juan-Pablo-Montes

5 DF Victor-Bernardez

6 DF Juan-Carlo--Garcia

7 DF Emilio-Izaguirre

8 MF Wilson-Palacios

9 FW Jerry-Palacios

10 MF Mario-Martinez

11 FW Jerry-Bengtson

Mexico CONCACAF 20

1 GK Jose-de-Jesus-Corona

2 DF Francisco-Javier-Rodriguez

3 DF Carlos-Salcido

4 DF Rafael-Marquez

5 DF Diego-Reyes

6 MF Hector-Herrera

7 DF Miguel-Layun

8 MF Marco-Fabian

9 FW Raul-Jimenez

10 FW Giovani-dos-Santos

11 FW Alan-Pulido

United_States CONCACAF 13

1 GK Tim-Howard

2 DF DeAndre-Yedlin

3 DF Omar-Gonzalez

4 MF Michael-Bradley

5 DF Matt-Besler

6 DF John-Brooks

7 DF DaMarcus-Beasley

8 FW Clint-Dempsey

9 FW Aron-Johannsson

10 MF Mix-Diskerud

11 MF Alejandro-Bedoya

Argentina CONMEBOL 5

1 GK Sergio-Romero

2 DF Ezequiel-Garay

3 DF Hugo-Campagnaro

4 DF Pablo-Zabaleta

5 MF Fernando-Gago

6 MF Lucas-Biglia

7 MF angel-Di-Maria

8 MF Enzo-Perez

9 FW Gonzalo-Higuain

10 FW Lionel-Messi

11 MF Maxi-Rodriguez

Brazil(hosts) CONMEBOL 3

1 GK Jefferson

2 DF Dani-Alves

3 DF Thiago-Silva

4 DF David-Luiz

5 MF Fernandinho

6 DF Marcelo

7 FW Hulk

8 MF Paulinho

9 FW Fred

10 FW Neymar

11 MF Oscar

Chile CONMEBOL 14

1 GK Claudio-Bravo

2 DF Eugenio-Mena

3 DF Miiko-Albornoz

4 MF Mauricio-Isla

5 MF Francisco-Silva

6 MF Carlos-Carmona

7 FW Alexis-Sanchez

8 MF Arturo-Vidal

9 FW Mauricio-Pinilla

10 MF Jorge-Valdivia

11 FW Eduardo-Vargas

Colombia CONMEBOL 8

1 GK David-Ospina

2 DF Cristian-Zapata

3 DF Mario-Yepes

4 DF Santiago-Arias

5 MF Carlos-Carbonero

6 DF Pablo-Armero

7 MF Abel-Aguilar

8 FW Teofilo-Gutierrez

9 MF James-Rodriguez

10 MF Juan-Guillermo

11 GK Camil-Vargas

Ecuador CONMEBOL 26

1 GK Maximo-Banguera

2 DF Jorge-Guagua

3 DF Frickson-Erazo

4 DF Juan-Carlos-Paredes

5 MF Renato-Ibarra

6 MF Christian-Noboa

7 MF Jefferson-Montero

8 MF edison-Mendez

9 MF Joao-Rojas

10 DF Walter-Ayovi

11 FW Felipe-Caicedo

Uruguay CONMEBOL 7

1 GK Fernando-Muslera

2 DF Diego-Lugano

3 DF Diego-Godin

4 DF Jorge-Fucile

5 MF Walter-Gargano

6 MF alvaro-Pereira

7 MF Cristian-Rodríguez

8 FW Abel-Hernández

9 FW Luis-Suarez

10 FW Diego-Forlan

11 FW Christian-Stuani

Belgium UEFA 11

1 GK Thibaut-Courtois

2 DF Toby-Alderweireld

3 DF Thomas-Vermaelen

4 DF Vincent-Kompany

5 DF Jan-Vertonghen

6 MF Axel-Witsel

7 MF Kevin-De-Bruyne

8 MF Marouane-Fellaini

9 FW Romelu-Lukaku

10 MF Eden-Hazard

11 MF Kevin-Mirallas

Bosnia_Herzegovina UEFA 21

1 GK Asmir-Begovi

2 DF Avdija-Vrajevi

3 DF Ermin-Biaki

4 DF Emir-Spahi

5 DF Sead-Kolainac

6 DF Ognjen-Vranje

7 DF Muhamed-Bei

8 MF Miralem-Pjani

9 FW Vedad-Ibievi

10 MF Zvjezdan-Misimovi

11 FW Edin-Deko

Croatia UEFA 18

1 GK Stipe-Pletikosa

2 DF time-Vrsaljko

3 DF Danijel-Pranji

4 MF Ivan-Perii

5 DF Vedran-orluka

6 DF Dejan-Lovren

7 MF Ivan-Rakit

8 MF Ognjen-Vukojevi

9 FW Nikica-Jelavi

10 MF Luk-Modri

11 DF Darijo-Srna

England UEFA 10

1 GK Joe-Hart

2 DF Glen-Johnson

3 DF Leighton-Baines

4 MF Steven-Gerrard

5 DF Gary-Cahill

6 DF Phil-Jagielka

7 MF Jack-Wilshere

8 MF Frank-Lampard

9 FW Daniel-Sturridge

10 FW Wayne-Rooney

11 FW Danny-Welbeck

France UEFA 17

1 GK Hugo-Lloris

2 DF Mathieu-Debuchy

3 DF Patrice-Evra

4 DF Rapha?l-Varane

5 DF Mamadou-Sakho

6 MF Yohan-Cabaye

7 MF Remy-Cabella

8 MF Mathieu-Valbuena

9 FW Olivier-Giroud

10 FW Karim-Benzema

11 MF Antoine-Griezmann

Germany UEFA 2

1 GK Manuel-Neuer

2 DF Kevin-Gro?kreutz

3 DF Matthias-Ginter

4 DF Benedikt-H?wedes

5 DF Mats-Hummels

6 MF Sami-Khedira

7 MF Bastian-Schweinsteiger

8 MF Mesut-?zil

9 MF Andre-Schurrle

10 FW Lukas-Podolski

11 FW Miroslav-Klose

Greece UEFA 12

1 GK Orestis-Karnezis

2 MF Giannis-Maniatis

3 DF Giorgos-Tzavellas

4 DF Kostas-Manolas

5 DF Vangelis-Moras

6 MF Alexandros-Tziolis

7 FW Georgios-Samaras

8 MF Panagiotis-Kone

9 FW Kostas-Mitroglou

10 MF Giorgos-Karagounis

11 DF Loukas-Vyntra

Italy UEFA 9

1 GK Gianluigi-Buffon

2 DF Mattia-De-Sciglio

3 DF Giorgi-Chiellini

4 DF Matteo-Darmian

5 MF Thiago-Motta

6 MF Antonio-Candreva

7 DF Ignazio-Abate

8 MF Claudio-Marchisio

9 FW Mario-Balotelli

10 FW Antoni-Cassano

11 FW Alessio-Cerci

Netherlands UEFA 15

1 GK Jasper-Cillessen

2 DF Ron-Vlaar

3 DF Stefan-de-Vrij

4 DF Bruno-Martins-Indi

5 DF Daley-Blind

6 MF Nigel-de-Jong

7 DF Daryl-Janmaat

8 MF Jonathan-de-Guzman

9 FW Robin-van-Persie

10 MF Wesley-Sneijder

11 FW Arjen-Robben

Portugal UEFA 4

1 GK Eduardo

2 DF Bruno-Alves

3 DF Pepe

4 MF Miguel-Veloso

5 DF Fabio-Coentr?o

6 MF William-Carvalho

7 FW Cristiano-Ronaldo

8 MF Jo?o-Moutinho

9 FW Hugo-Almeida

10 MF Vieirinha

11 FW eder

Russia UEFA 19

1 GK Igor-Akinfeev

2 DF Aleksei-Kozlov

3 DF Georgi-Shchennikov

4 DF Sergei-Ignashevich

5 DF Andrei-Semyonov

6 FW Maksim-Kanunnikov

7 MF Igor-Denisov

8 MF Denis-Glushakov

9 FW Aleksandr-Kokorin

10 MF Alan-Dzagoev

11 FW Aleksandr-Kerzhakov

Spain UEFA 1

1 GK Iker-Casillas

2 DF Rail-Albiol

3 DF Gerar-ique

4 MF Javi-Martinez

5 DF Juanfran

6 MF Andres-Iniesta

7 FW David-Villa

8 MF Xavi

9 FW Fernando-Torres

10 MF Cesc-Fabregas

11 FW Pedro

Switzerland UEFA 6

1 GK Diego-Benaglio

2 DF Stephan-Lichtsteiner

3 DF Reto-Ziegler

4 DF Philippe-Senderos

5 DF Steve-von-Bergen

6 DF Michael-Lang

7 MF Tranquillo-Barnetta

8 MF G?khan-Inler

9 FW Haris-Seferovi?

10 MF Granit-Xhaka

11 MF Valon-Behrami

祝大家支持的球队获胜~~~ (没获胜我也没办法, 你们看着办吧O(∩_∩)O )

原创求顶!!!

--by 万山之巅

相关推荐