首页 > 代码库 > 完全模拟FIFA2014世界杯 原创求顶!

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

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

FIFA2014世界杯模拟器

           你值得拥有

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

  1 #include <iostream>  2 #include <string>  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 team129 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-10173      this->member[i] = p;174 175 }176 player team::get_member(int i) { // 传入参数是位置0-10177      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 <iostream>   2 #include <fstream>   3 #include <string>   4 #include <vector>   5 #include <ctime>   6 #include <cstdlib>   7 #include <iomanip>   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..." <<endl;  33     log << "playing..." <<endl;  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." <<endl;  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." <<endl;  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." <<endl;  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." <<endl;  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..." <<endl; 101     log << "playing..." <<endl; 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." <<endl; 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." <<endl; 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." <<endl; 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." <<endl; 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 << ")" <<endl; 198 input << "AFC (" << count << ")" <<endl; 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 << ")" <<endl; 213 input << "CAF (" << count << ")" <<endl; 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 << ")" <<endl; 228 input << "UEFA (" << count << ")" <<endl; 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 << ")" <<endl; 243 input << "CONCACAF (" << count << ")" <<endl; 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 << ")" <<endl; 258 input << "CONMEBOL (" << count << ")" <<endl; 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<team> pot[4];// 4档 268 vector<team> 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<team>::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: "<<endl; 353 file << "After first draw: "<<endl; 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<group[i].size();j++) { 389         //debug << group[i][j].get_name() << " "; 390     } 391     //debug << endl; 392 } 393 //debug.close(); 394 //  目标 vector<team> 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:" <<endl; 405 file << "The Final Draw:" <<endl; 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<int, int > 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&atildeo","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" <<endl; 493 file << "Matches by squads" <<endl; 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 <<endl; 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 <<endl; 505             } 506         } 507     } 508 } 509  510 cout << "\nMatches by dates" <<endl; 511 file << "\nMatches by dates" <<endl; 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" <<endl; 687 file << "Matches by dates" <<endl; 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" <<endl; 804 file << "Matches by dates" <<endl; 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" <<endl; 922 file << "Matches by dates" <<endl; 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" <<endl;1043 file << "Matches by dates" <<endl;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 teams1137 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 <<endl;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 621    GK    Mathew-Ryan2    DF    Ivan-Franjic3    DF    Jason-Davidson4    FW    Tim-Cahill5    MF    Mark-Milligan6    DF    Matthew-?piranovi?7    FW    Mathew-Leckie8    DF    Bailey-Wright9    FW    Adam-Taggart10    MF    Ben-Halloran11    MF    Tommy-OarIran AFC 431    GK    Rahman-Ahmadi2    MF    Khosro-Heydari3    MF    Ehsa-Hajsafi4    DF    Jalal-Hosseini5    DF    Amir-Hossein-Sadeghi6    MF    Javad-Nekounam7    MF    Masoud-Shojaei8    MF    Reza-Haghighi9    FW    Alireza-Jahanbakhsh10    FW    Karim-Ansarifard11    MF    Ghasem-HaddadifarJapan AFC 461    GK    Eiji-Kawashima2    DF    Atsuto-Uchida3    DF    Gotoku-Sakai4    MF    Keisuke-Honda5    DF    Yuto-Nagatomo6    DF    Masato-Morishige7    MF    Yasuhito-Endo8    MF    Hiroshi-Kiyotake9    FW    Shinji-Okazaki10    MF    Shinji-Kagawa11    FW    Yoichiro-KakitaniSouth_Korea AFC 571    GK    Jung-Sung-ryong2    DF    Kim-Chang-soo3    DF    Yun-Suk-young4    DF    Kwak-Tae-hwi5    DF    Kim-Young-gwon6    DF    Hwang-Seok-ho7    MF    Kim-Bo-kyung8    MF    Ha-Dae-sung9    FW    Son-Heung-min10    FW    Park-Chu-young11    FW    Lee-Keun-hoAlgeria CAF 221    GK    Cedric-Si-Mohamed2    DF    Madjid-Bougherra3    DF    Faouzi-Ghoulam4    DF    Essa?d-Belkalem5    DF    Rafik-Halliche6    DF    Djamel-Mesbah7    MF    Hassan-Yebda8    MF    Medhi-Lacen9    MF    Sofiane-Feghouli10    MF    Yacine-Brahimi11    DF    Carl-MedjaniCameroon CAF 561    GK    Lo?c-Feudjou2    DF    Beno?t-Assou-Ekotto3    DF    Nicolas-NKoulou4    DF    Cedric-Djeugoue5    DF    Dany-Nounkeu6    MF    Alex-Song7    MF    Landry-NGuemo8    FW    Benjamin-Moukandjo9    FW    Samuel-Etoo10    FW    Vincent-Aboubakar11    MF    Jean-MakounGhana CAF 371    GK    Stephen-Adams2    DF    Samuel-Inkoom3    FW    Asamoah-Gyan4    DF    Daniel-Opare5    MF    Michael-Essien6    MF    Afriyie-Acquah7    MF    Christian-Atsu8    MF    Emmanuel-Agyemang-Badu9    FW    Kevin-Prince-Boateng10    MF    Andre-Ayew11    MF    Sulley-MuntariIvory_Coast CAF 231    GK    Boubacar-Barry2    DF    Ousmane-Viera3    DF    Arthur-Boka4    DF    Kolo-Toure5    DF    Didier-Zokora6    FW    Mathis-Bolly7    DF    Jean-Daniel-Akpa-Akpro8    FW    Salomon-Kalou9    MF    Cheick-Tiote10    FW    Gervinho11    FW    Didier-DrogbaNigeria CAF 441    GK    Vincent-Enyeama2    DF    Joseph-Yobo3    MF    Ejike-Uzoenyi4    MF    Reuben-Gabriel5    DF    Efe-Ambrose6    DF    Azubuike-Egwuekwe7    FW    Ahmed-Musa8    FW    Peter-Odemwingie9    FW    Emmanuel-Emenike10    MF    John-Obi-Mikel11    MF    Victor-MosesCosta_Rica CONCACAF 281    GK    Keylor-Navas2    DF    Johnny-Acosta3    DF    Giancarlo-Gonzalez4    DF    Michael-Uma?a5    MF    Celso-Borges6    DF    oscar-Duarte7    MF    Christian-Bola?os8    DF    David-Myrie9    FW    Joel-Campbell10    FW    Bryan-Ruiz11    MF    Michael-BarrantesHonduras CONCACAF 331    GK    Luis-Lopez2    DF    Osman-Chavez3    DF    Maynor-Figueroa4    DF    Juan-Pablo-Montes5    DF    Victor-Bernardez6    DF    Juan-Carlo--Garcia7    DF    Emilio-Izaguirre8    MF    Wilson-Palacios9    FW    Jerry-Palacios10    MF    Mario-Martinez11    FW    Jerry-BengtsonMexico CONCACAF 201    GK    Jose-de-Jesus-Corona2    DF    Francisco-Javier-Rodriguez3    DF    Carlos-Salcido4    DF    Rafael-Marquez5    DF    Diego-Reyes6    MF    Hector-Herrera7    DF    Miguel-Layun8    MF    Marco-Fabian9    FW    Raul-Jimenez10    FW    Giovani-dos-Santos11    FW    Alan-PulidoUnited_States CONCACAF 131    GK    Tim-Howard2    DF    DeAndre-Yedlin3    DF    Omar-Gonzalez4    MF    Michael-Bradley5    DF    Matt-Besler6    DF    John-Brooks7    DF    DaMarcus-Beasley8    FW    Clint-Dempsey9    FW    Aron-Johannsson    10    MF    Mix-Diskerud11    MF    Alejandro-BedoyaArgentina CONMEBOL 5 1    GK    Sergio-Romero2    DF    Ezequiel-Garay3    DF    Hugo-Campagnaro4    DF    Pablo-Zabaleta5    MF    Fernando-Gago6    MF    Lucas-Biglia7    MF    angel-Di-Maria8    MF    Enzo-Perez9    FW    Gonzalo-Higuain    10    FW    Lionel-Messi11    MF    Maxi-RodriguezBrazil(hosts) CONMEBOL 31    GK    Jefferson2    DF    Dani-Alves3    DF    Thiago-Silva4    DF    David-Luiz5    MF    Fernandinho6    DF    Marcelo7    FW    Hulk8    MF    Paulinho9    FW    Fred10    FW    Neymar11    MF    OscarChile CONMEBOL 14 1    GK    Claudio-Bravo2    DF    Eugenio-Mena3    DF    Miiko-Albornoz4    MF    Mauricio-Isla5    MF    Francisco-Silva6    MF    Carlos-Carmona7    FW    Alexis-Sanchez8    MF    Arturo-Vidal9    FW    Mauricio-Pinilla10    MF    Jorge-Valdivia11    FW    Eduardo-VargasColombia CONMEBOL 8 1    GK    David-Ospina2    DF    Cristian-Zapata    3    DF    Mario-Yepes4    DF    Santiago-Arias5    MF    Carlos-Carbonero6    DF    Pablo-Armero7    MF    Abel-Aguilar8    FW    Teofilo-Gutierrez9    MF    James-Rodriguez    10    MF    Juan-Guillermo11    GK    Camil-VargasEcuador CONMEBOL 26 1    GK    Maximo-Banguera    2    DF    Jorge-Guagua3    DF    Frickson-Erazo4    DF    Juan-Carlos-Paredes5    MF    Renato-Ibarra6    MF    Christian-Noboa7    MF    Jefferson-Montero8    MF    edison-Mendez9    MF    Joao-Rojas10    DF    Walter-Ayovi11    FW    Felipe-CaicedoUruguay CONMEBOL 7 1    GK    Fernando-Muslera2    DF    Diego-Lugano3    DF    Diego-Godin4    DF    Jorge-Fucile5    MF    Walter-Gargano6    MF    alvaro-Pereira7    MF    Cristian-Rodríguez8    FW    Abel-Hernández9    FW    Luis-Suarez10    FW    Diego-Forlan11    FW    Christian-StuaniBelgium UEFA 111    GK    Thibaut-Courtois2    DF    Toby-Alderweireld3    DF    Thomas-Vermaelen4    DF    Vincent-Kompany5    DF    Jan-Vertonghen6    MF    Axel-Witsel7    MF    Kevin-De-Bruyne8    MF    Marouane-Fellaini9    FW    Romelu-Lukaku10    MF    Eden-Hazard11    MF    Kevin-MirallasBosnia_Herzegovina UEFA 211    GK    Asmir-Begovi2    DF    Avdija-Vrajevi3    DF    Ermin-Biaki4    DF    Emir-Spahi5    DF    Sead-Kolainac6    DF    Ognjen-Vranje7    DF    Muhamed-Bei8    MF    Miralem-Pjani9    FW    Vedad-Ibievi10    MF    Zvjezdan-Misimovi11    FW    Edin-DekoCroatia UEFA 181    GK    Stipe-Pletikosa2    DF    time-Vrsaljko3    DF    Danijel-Pranji4    MF    Ivan-Perii5    DF    Vedran-orluka6    DF    Dejan-Lovren7    MF    Ivan-Rakit8    MF    Ognjen-Vukojevi9    FW    Nikica-Jelavi10    MF    Luk-Modri11    DF    Darijo-SrnaEngland UEFA 10 1    GK    Joe-Hart2    DF    Glen-Johnson3    DF    Leighton-Baines4    MF    Steven-Gerrard5    DF    Gary-Cahill6    DF    Phil-Jagielka7    MF    Jack-Wilshere8    MF    Frank-Lampard9    FW    Daniel-Sturridge10    FW    Wayne-Rooney11    FW    Danny-WelbeckFrance UEFA 171    GK    Hugo-Lloris2    DF    Mathieu-Debuchy3    DF    Patrice-Evra4    DF    Rapha?l-Varane5    DF    Mamadou-Sakho6    MF    Yohan-Cabaye7    MF    Remy-Cabella8    MF    Mathieu-Valbuena9    FW    Olivier-Giroud10    FW    Karim-Benzema11    MF    Antoine-GriezmannGermany UEFA 21    GK    Manuel-Neuer2    DF    Kevin-Gro?kreutz    3    DF    Matthias-Ginter4    DF    Benedikt-H?wedes5    DF    Mats-Hummels6    MF    Sami-Khedira7    MF    Bastian-Schweinsteiger8    MF    Mesut-?zil9    MF    Andre-Schurrle    10    FW    Lukas-Podolski11    FW    Miroslav-KloseGreece UEFA 121    GK    Orestis-Karnezis2    MF    Giannis-Maniatis3    DF    Giorgos-Tzavellas4    DF    Kostas-Manolas5    DF    Vangelis-Moras6    MF    Alexandros-Tziolis7    FW    Georgios-Samaras8    MF    Panagiotis-Kone9    FW    Kostas-Mitroglou10    MF    Giorgos-Karagounis11    DF    Loukas-VyntraItaly UEFA 91    GK    Gianluigi-Buffon2    DF    Mattia-De-Sciglio3    DF    Giorgi-Chiellini4    DF    Matteo-Darmian5    MF    Thiago-Motta6    MF    Antonio-Candreva7    DF    Ignazio-Abate8    MF    Claudio-Marchisio9    FW    Mario-Balotelli10    FW    Antoni-Cassano11    FW    Alessio-CerciNetherlands UEFA 151    GK    Jasper-Cillessen2    DF    Ron-Vlaar3    DF    Stefan-de-Vrij4    DF    Bruno-Martins-Indi5    DF    Daley-Blind6    MF    Nigel-de-Jong7    DF    Daryl-Janmaat8    MF    Jonathan-de-Guzman9    FW    Robin-van-Persie10    MF    Wesley-Sneijder11    FW    Arjen-RobbenPortugal UEFA 41    GK    Eduardo2    DF    Bruno-Alves3    DF    Pepe4    MF    Miguel-Veloso5    DF    Fabio-Coentr?o6    MF    William-Carvalho7    FW    Cristiano-Ronaldo8    MF    Jo?o-Moutinho9    FW    Hugo-Almeida10    MF    Vieirinha11    FW    ederRussia UEFA 191    GK    Igor-Akinfeev2    DF    Aleksei-Kozlov3    DF    Georgi-Shchennikov4    DF    Sergei-Ignashevich5    DF    Andrei-Semyonov6    FW    Maksim-Kanunnikov7    MF    Igor-Denisov8    MF    Denis-Glushakov9    FW    Aleksandr-Kokorin10    MF    Alan-Dzagoev11    FW    Aleksandr-KerzhakovSpain UEFA 11    GK    Iker-Casillas2    DF    Rail-Albiol3    DF    Gerar-ique4    MF    Javi-Martinez5    DF    Juanfran6    MF    Andres-Iniesta7    FW    David-Villa8    MF    Xavi9    FW    Fernando-Torres10    MF    Cesc-Fabregas11    FW    PedroSwitzerland UEFA 61    GK    Diego-Benaglio2    DF    Stephan-Lichtsteiner3    DF    Reto-Ziegler4    DF    Philippe-Senderos5    DF    Steve-von-Bergen6    DF    Michael-Lang7    MF    Tranquillo-Barnetta8    MF    G?khan-Inler9    FW    Haris-Seferovi?10    MF    Granit-Xhaka11    MF    Valon-Behrami

 

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

原创求顶!!!

      --by 万山之巅

    

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