-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAirplane_System.hpp
750 lines (715 loc) · 27.5 KB
/
Airplane_System.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
//
// Airplane_System.hpp
// Iplane
//
// Created by 杨溢 管清泉 陆子旭 on 2017/12/22.
// Copyright © 2017年 杨溢 管清泉 陆子旭. All rights reserved.
//
#ifndef Airplane_System_hpp
#define Airplane_System_hpp
#include "stdafx.h"
#include <string>
#include <stdio.h>
#include <fstream>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
//定义一个飞机订票系统的类
class Airplane_System
{
public:
//基本函数
Airplane_System(); //构造函数
Airplane_System(string, string, string, string); //构造函数(包含文件名)
~Airplane_System(); //析构函数
//用户操作
void Register(string, string, bool); //注册
void SignIn(string, string); //登录
//题目要求
void dataloading(); //航班信息录入
void current_information_view(); //航班信息浏览
void check_information(string); //航班信息查询
void ticket_booking(string, string, long long); //订票
void ticket_returning(string, string, long long); //退票
void flight_list(int, long long, long long, string, string); //相应航班排序
void flight_recommended(long long, long long, string, string); //航班线路设计
void output_route(); //航班网络输出
void best_route_recommended
(int, long long, long long, string, string); //最优航班线路推荐
private:
//文件名
string FlightFile; //航班信息文件
string UserFile; //用户名信息文件
string OutFile; //输出文件
string BoolFile; //判断文件
//航班数组相关
//定义一个航班信息的类
struct flight {
public:
string starting_point; //起始城市
string finishing_point; //到达城市
string company; //所属公司
string flight_number; //航班号
long long start_time; //起飞时间
long long finish_time; //到达时间
int price; //飞机票价
double discount; //票价折扣
int seat_number; //座位总数
int book_number; //已预定总数
};
//表头
struct {
string flight_number; //航班号
string starting_point; //起始城市
string finishing_point; //到达城市
string start_time; //起飞时间
string finish_time; //到达时间
string price; //飞机票价
string discount; //票价折扣
string company; //所属公司
string seat_number; //座位总数
string book_number; //已预定总数
} flight_table;
int number_of_city; //开放航线的城市个数
int total; //航班总数
vector <flight> flight_totalnumber; //flight数组(暂时不得进行排序,删除,添加元素等操作)
void DataWrite(); //航班信息输出
//邻接表相关
//边链表
struct edge
{
int next_point; //终点城市
int flight_node; //航班节点信息(vector数组下标)
edge* next; //下一条边
};
//顶点数组
struct point
{
string cityname; //城市名称
edge* address; //边链表的头指针
};
vector <point> point_link; //邻接表顶点数组
//用户相关
//一个用户
struct User {
string name;
string password;
bool IsAdministrator;
vector<flight> information;
}ThisUser; //当前用户
vector<User> UsersInformation; //记录所有用户的数组
void ReadUsers(); //读入用户信息
void WriteUsers(); //输出用户信息
//公用相关函数
void print_flight_data(); //输出航班信息
void print_flight_data(flight); //输出航班信息
void print_flight_data(flight, string); //输出航班信息
void print_lzx(int); //输出判断函数
//输出航班数组(用于第七题和第九题)
vector<queue<int>> flight_queue(long long, long long, string, string);
//用于vector的相关函数
//用于vector<flight>的起始时间排序函数
static bool vector_start_time_compare(const flight &a, const flight &b) {
return a.start_time < b.start_time;
}
//用于vector<flight>的价格排序函数
static bool vector_price_compare(const flight &a, const flight &b) {
return a.price < b.price;
}
//用于vector<point>的查找函数(自定义类的方式实现)
class findx {
private: string test;
public:
findx(const string str) :test(str) {}
bool operator()(point& dValue) {
if (dValue.cityname == test) return true;
else return false;
}
};
//用于vector<User>的查找函数(自定义类的方式实现)
class findu {
private: string test;
public:
findu(const string str) :test(str) {}
bool operator()(User& dValue) {
if (dValue.name == test) return true;
else return false;
}
};
//用于vector<flight>的查找函数(自定义类的方式实现)
class findi {
private: string test1; long long test2;
public:
findi(const string s, const long long t) :test1(s), test2(t) {}
bool operator()(flight& dValue) {
if (dValue.flight_number == test1&&
dValue.start_time == test2) return true;
else return false;
}
};
};
//构造函数
Airplane_System::Airplane_System() {
}
//构造函数(包含文件名) by 陆子旭
//参数分别为:
//航班文件名(file1);
//用户文件名(file2);
//输出文件名(file3);
//判断文件名(file4);
Airplane_System::Airplane_System(string file1, string file2, string file3, string file4) :
FlightFile(file1), UserFile(file2), OutFile(file3), BoolFile(file4) {
}
//析构函数
Airplane_System::~Airplane_System() {
}
//航班信息输出 by 陆子旭
void Airplane_System::DataWrite() {
ofstream file(FlightFile, ios::trunc);
//输出表头
file << flight_table.starting_point << '\t' << flight_table.finishing_point << '\t' << flight_table.company << '\t' << flight_table.flight_number << '\t' << flight_table.start_time << '\t' << flight_table.finish_time << '\t' << flight_table.price << '\t' << flight_table.discount << '\t' << flight_table.seat_number << '\t' << flight_table.book_number << endl;
//输出数据
for (int i = 0; i < flight_totalnumber.size(); i++) {
print_flight_data(flight_totalnumber[i], FlightFile);
}
}
//读入用户信息 by 杨溢 陆子旭
void Airplane_System::ReadUsers() {
ifstream file(UserFile); //文件
User temp_user; //临时用户
flight temp_flight; //临时航班
int ticket_num; //已定航班数
//读用户信息
while (file.good()) {
file >> temp_user.name;
file >> temp_user.password;
file >> temp_user.IsAdministrator;
file >> ticket_num;
for (int i = 0; i<ticket_num; i++) {
file >> temp_flight.starting_point;
file >> temp_flight.finishing_point;
file >> temp_flight.company;
file >> temp_flight.flight_number;
file >> temp_flight.start_time;
file >> temp_flight.finish_time;
file >> temp_flight.price;
file >> temp_flight.discount;
file >> temp_flight.seat_number;
file >> temp_flight.book_number;
temp_user.information.push_back(temp_flight);
}
UsersInformation.push_back(temp_user);
temp_user.information.clear();
file.get();file.get(); if (file.peek() == EOF) break;
}
}
//输出用户信息 by 陆子旭
void Airplane_System::WriteUsers() {
ofstream file(UserFile, ios::trunc); //文件
//输出用户信息
for (int i = 0; i < UsersInformation.size(); i++) {
file << UsersInformation[i].name << '\t' << UsersInformation[i].password << '\t' << UsersInformation[i].IsAdministrator << '\t' << UsersInformation[i].information.size() << endl;
for (int j = 0; j < UsersInformation[i].information.size(); j++) {
file.close();
print_flight_data(UsersInformation[i].information[j], UserFile);
file.open(UserFile, ios::app);
}
file << endl;
}
file.close();
}
//注册 by 陆子旭
//参数分别为:
//用户名(nam);
//密码(pas);
//是否为管理员(bo);
void Airplane_System::Register(string nam, string pas, bool bo)
{
User temp;
temp.name = nam;
temp.password = pas;
temp.IsAdministrator = bo;
UsersInformation.push_back(temp);
}
//登录 by 陆子旭
//参数分别为:
//用户名(nam);
//密码(pas);
//BoolFile里面:0:用户名没找到;1:全部成功;1 0:密码错误;
//输出是管理员为true;不是为false;
void Airplane_System::SignIn(string nam, string pas) {
ReadUsers();
vector<User>::iterator result = find_if(UsersInformation.begin(), UsersInformation.end(), findu(nam));
if (result == UsersInformation.end()) {
print_lzx(-2);
return;
}else{
print_lzx(-1);
if (result->password == pas) {
ThisUser = *result;
}else{
ofstream file(BoolFile,ios::app);
file << '\t' << 0;
file.close();
return;
}
}
ofstream file(OutFile,ios::trunc);
file << ThisUser.IsAdministrator;
file.close();
}
//输出航班信息 by 陆子旭
//参数分别为:
//无参数直接在默认Outfile里面换行;
//航班类(temp);
//输出文件名(file_name)(默认Outfile);
void Airplane_System::print_flight_data() {
ofstream file(OutFile,ios::app);
file << endl;
file.close();
}
void Airplane_System::print_flight_data(flight temp) {
ofstream file(OutFile,ios::app);
file << temp.starting_point << '\t' << temp.finishing_point<< '\t' << temp.company <<
'\t' << temp.flight_number << '\t' << temp.start_time << '\t' << temp.finish_time <<
'\t' << temp.price << '\t' << temp.discount << '\t' << temp.seat_number << '\t' << temp.book_number << endl;
file.close();
}
void Airplane_System::print_flight_data(flight temp, string file_name) {
ofstream file(file_name,ios::app);
file << temp.starting_point << '\t' << temp.finishing_point<< '\t' << temp.company <<
'\t' << temp.flight_number << '\t' << temp.start_time << '\t' << temp.finish_time <<
'\t' << temp.price << '\t' << temp.discount << '\t' << temp.seat_number << '\t' << temp.book_number << endl;
file.close();
}
//输出判断函数 by 陆子旭
void Airplane_System::print_lzx(int temp_a) {
ofstream file(BoolFile, ios::trunc);
switch (temp_a) {
case -1:file << 1; break;
case -2:file << 0; break;
}
file.close();
}
//航班数组(用于第七题和第九题 by 陆子旭
//采用广度优先搜索
//参数分别为:
//对于起飞时间起始时间限制(timef_bool);
//对于起飞时间结束时间限制(timel_bool);
//起始城市(start_bool);
//到达城市(arrive_bool);
vector<queue<int>> Airplane_System::flight_queue(long long timef_bool = 201710310000,
long long timel_bool = 201712310000, string start_bool = "长春", string arrive_bool = "长春") {
vector<point>::iterator result; //vector迭代器
vector<queue<int>> temp_f; //航线数组
vector<queue<int>> temp_l; //航线最终数组
queue<int> temp_q; //临时队列
queue<int> Q, Q_f; //广度搜索队列
edge *p; //临时边
int j(0), k(0); //临时城市点
bool visit[5000]; //航班访问数组
for (int i = 0; i<total; i++) {
visit[i] = false;
}
//直达航线统计
result = find_if(point_link.begin(), point_link.end(), findx(start_bool));
p = result->address;
while (p) {
if (flight_totalnumber[p->flight_node].start_time>timef_bool&&
flight_totalnumber[p->flight_node].finish_time<timel_bool) {
temp_q.push(p->flight_node);
if (flight_totalnumber[p->flight_node].finishing_point == arrive_bool) {
temp_l.push_back(temp_q);
}
else {
temp_f.push_back(temp_q);
}
temp_q = queue<int>();
Q.push(p->next_point);
Q_f.push(p->flight_node);
visit[p->flight_node] = true;
}
p = p->next;
}
//非直达航线统计
while (!Q.empty()) {
j = Q.front();
Q.pop();
k = Q_f.front();
Q_f.pop();
p = point_link[j].address;
while (p) {
if (flight_totalnumber[p->flight_node].start_time > flight_totalnumber[k].finish_time&&
flight_totalnumber[p->flight_node].finish_time < timel_bool &&
!visit[p->flight_node]) {
for (int i = 0; i<int(temp_f.end() - temp_f.begin()); i++) {
if (flight_totalnumber[temp_f[i].back()].finishing_point == point_link[j].cityname&&
flight_totalnumber[temp_f[i].back()].finish_time <
flight_totalnumber[p->flight_node].start_time) {
temp_q = temp_f[i];
temp_q.push(p->flight_node);
if (flight_totalnumber[p->flight_node].finishing_point == arrive_bool) {
temp_l.push_back(temp_q);
}
else {
temp_f.push_back(temp_q);
}
temp_q = queue<int>();
}
}
Q.push(p->next_point);
Q_f.push(p->flight_node);
visit[p->flight_node] = true;
}
p = p->next;
}
}
return temp_l;
}
//信息录入 从文件录入到程序
//输出vector数组,邻接表 by 管清泉 陆子旭
void Airplane_System::dataloading() {
flight temp_flight; //临时航班类
point temp_point; //临时顶点节结点
edge *temp_edge1, *temp_edge2; //临时边结点
vector<point>::iterator result; //vector迭代器 可以用auto!!!(这句话是某个对auto有执念的人加上的)
ifstream file(FlightFile);
//读表头
if (!file.eof()) {
file >> flight_table.starting_point;
file >> flight_table.finishing_point;
file >> flight_table.company;
file >> flight_table.flight_number;
file >> flight_table.start_time;
file >> flight_table.finish_time;
file >> flight_table.price;
file >> flight_table.discount;
file >> flight_table.seat_number;
file >> flight_table.book_number;
}
while (file.good()) {
//统计航线数目
total++;
//读数据
file >> temp_flight.starting_point;
file >> temp_flight.finishing_point;
file >> temp_flight.company;
file >> temp_flight.flight_number;
file >> temp_flight.start_time;
file >> temp_flight.finish_time;
file >> temp_flight.price;
file >> temp_flight.discount;
file >> temp_flight.seat_number;
file >> temp_flight.book_number;
flight_totalnumber.push_back(temp_flight);
file.get(); if (file.peek() == EOF) break;//获取之后一个字符,避免最后一行读两遍
//生成邻接表
//判断终点城市结点
result = find_if(point_link.begin(), point_link.end(), findx(temp_flight.finishing_point));
if (result == point_link.end()) {
temp_point.cityname = temp_flight.finishing_point;
temp_point.address = NULL;
point_link.push_back(temp_point);
result = point_link.end() - 1;
}
//生成边结点
temp_edge1 = new edge;
temp_edge1->next_point = int(result - point_link.begin());
temp_edge1->flight_node = total - 1;
temp_edge1->next = NULL;
//判断起点城市结点
result = find_if(point_link.begin(), point_link.end(), findx(temp_flight.starting_point));
if (result == point_link.end()) {
temp_point.cityname = temp_flight.starting_point;
temp_point.address = NULL;
point_link.push_back(temp_point);
result = point_link.end() - 1;
}
//将边加入邻接表
if (!point_link[int(result - point_link.begin())].address) {
point_link[int(result - point_link.begin())].address = temp_edge1;
}
else {
temp_edge2 = point_link[int(result - point_link.begin())].address;
while (temp_edge2->next) {
temp_edge2 = temp_edge2->next;
}
temp_edge2->next = temp_edge1;
}
}
//城市数目
number_of_city = int(point_link.size());
}
//航班信息浏览 by 管清泉
void Airplane_System::current_information_view() {
}
//航班信息查询 by 陆子旭
//参数分别为:
//航班号(flight_num);
void Airplane_System::check_information(string flight_num) {
ofstream file(OutFile,ios::trunc);file.close(); //清空输出文件
for (int i = 0; i <total; i++) {
if (flight_totalnumber[i].flight_number == flight_num) {
print_flight_data(flight_totalnumber[i]);
}
}
}
//订票 by 杨溢 陆子旭
//参数分别为:
//用户名(user_name);
//航班号(flight_num);
//起飞时间(time);
void Airplane_System::ticket_booking(string user_name, string flight_num, long long time) {
ReadUsers();
//判断并修改数据
for (int i = 0; i <total; i++) {
if (flight_totalnumber[i].flight_number == flight_num&&
flight_totalnumber[i].start_time == time) {
if (flight_totalnumber[i].book_number < flight_totalnumber[i].seat_number) {
//改变航班大数组
flight_totalnumber[i].book_number++;
//改变用户数据
vector<User>::iterator result = find_if(UsersInformation.begin(), UsersInformation.end(), findu(user_name));
if (result == UsersInformation.end()) {
print_lzx(-2);
return;
}
else {
result->information.push_back(flight_totalnumber[i]);
}
for (result = UsersInformation.begin(); result != UsersInformation.end(); result++) {
for (vector<flight>::iterator j = result->information.begin();
j != result->information.end(); j++) {
if (j->flight_number == flight_num && j->start_time == time) {
*j = flight_totalnumber[i];
}
}
}
}
else {
print_lzx(-2);
return;
}
break;
}
}
DataWrite();
WriteUsers();
print_lzx(-1);
}
//退票 by 陆子旭
//参数分别为:
//用户名(user_name);
//航班号(flight_num);
//起飞时间(time);
void Airplane_System::ticket_returning(string user_name, string flight_num, long long time) {
ReadUsers();
//判断并修改数据
for (int i = 0; i <total; i++) {
if (flight_totalnumber[i].flight_number == flight_num&&
flight_totalnumber[i].start_time == time) {
if (flight_totalnumber[i].book_number > 0) {
//改变航班大数组
flight_totalnumber[i].book_number--;
//改变用户数据
vector<User>::iterator result = find_if(UsersInformation.begin(), UsersInformation.end(), findu(user_name));
if (result == UsersInformation.end()) {
print_lzx(-2);
return;
}
else {
vector<flight>::iterator j =
find_if(result->information.begin(), result->information.end(), findi(flight_num, time));
j = result->information.erase(j);
}
for (result = UsersInformation.begin(); result != UsersInformation.end(); result++) {
for (vector<flight>::iterator j = result->information.begin();
j != result->information.end(); j++) {
if (j->flight_number == flight_num && j->start_time == time) {
*j = flight_totalnumber[i];
}
}
}
}
else {
print_lzx(-2);
return;
}
break;
}
}
DataWrite();
WriteUsers();
print_lzx(-1);
}
//相应航班排序 by 陆子旭
//升降序(sort_bool): 1为时间从低到高,2为时间从高到低,3为价格从低到高,4为价格从高到低;
//对于起飞时间起始时间限制(timef_bool);
//对于起飞时间结束时间限制(timel_bool);
//起始城市(start_bool);
//到达城市(arrive_bool);
void Airplane_System::flight_list(int sort_bool = 1, long long timef_bool = 201710310000,
long long timel_bool = 201712310000, string start_bool = "长春", string arrive_bool = "长春") {
ofstream file(OutFile,ios::trunc);file.close(); //清空输出文件
vector<flight> temp; //临时中间量
int sum(0); //总数
//筛选
for (int i = 0; i <total; i++) {
if (flight_totalnumber[i].start_time > timef_bool&&
flight_totalnumber[i].finish_time < timel_bool&&
flight_totalnumber[i].starting_point == start_bool&&
flight_totalnumber[i].finishing_point == arrive_bool
) {
temp.push_back(flight_totalnumber[i]);
}
}
sum = int(temp.size());
//根据不同选择进行排列
if (sum == 0) {
print_lzx(-2);
return;
}
switch (sort_bool) {
case 1:
sort(temp.begin(), temp.end(), vector_start_time_compare);
for (int i = 0; i <sum; i++) {
print_flight_data(temp[i]);
}
break;
case 2:
sort(temp.begin(), temp.end(), vector_start_time_compare);
for (int i = sum - 1; i >= 0; i--) {
print_flight_data(temp[i]);
}
break;
case 3:
sort(temp.begin(), temp.end(), vector_price_compare);
for (int i = 0; i <sum; i++) {
print_flight_data(temp[i]);
}
break;
case 4:
sort(temp.begin(), temp.end(), vector_price_compare);
for (int i = sum - 1; i >= 0; i--) {
print_flight_data(temp[i]);
}
break;
default:
print_lzx(-2);
return;
}
print_lzx(-1);
}
//航班线路设计 by 陆子旭
//参数分别为:
//对于起飞时间起始时间限制(timef_bool);
//对于起飞时间结束时间限制(timel_bool);
//起始城市(start_bool);
//到达城市(arrive_bool);
void Airplane_System::flight_recommended(long long timef_bool = 201710310000, long long timel_bool = 201712310000,
string start_bool = "长春", string arrive_bool = "长春") {
ofstream file(OutFile,ios::trunc);file.close(); //清空输出文件
queue<int> temp_q; //临时队列
vector<queue<int>> temp_l; //航线最终数组
//调用函数
temp_l = flight_queue(timef_bool, timel_bool, start_bool, arrive_bool);
//输出
if (temp_l.size() == 0) {
print_lzx(-2);
return;
}
for (vector<queue<int>>::iterator i = temp_l.begin(); i != temp_l.end(); i++) {
temp_q = *i;
while (!temp_q.empty()) {
print_flight_data(flight_totalnumber[temp_q.front()]);
temp_q.pop();
}
print_flight_data();
}
print_lzx(-1);
}
//航班网络输出 by 杨溢
void Airplane_System::output_route() {
}
//最优航班线路推荐 by 陆子旭
//参数分别为:
//升降序(sort_bool): 1取最短时间,2取最低价格;
//对于起飞时间起始时间限制(timef_bool);
//对于起飞时间结束时间限制(timel_bool);
//起始城市(start_bool);
//到达城市(arrive_bool);
void Airplane_System::best_route_recommended(int sort_bool = 1, long long timef_bool = 201710310000,
long long timel_bool = 201712310000, string start_bool = "长春",
string arrive_bool = "长春") {
ofstream file(OutFile,ios::trunc);file.close(); //清空输出文件
vector<queue<int>> temp_l; //航线最终数组
queue<int> temp_q; //临时队列
//调用函数
temp_l = flight_queue(timef_bool, timel_bool, start_bool, arrive_bool);
//取最优
if (temp_l.size() == 0) {
print_lzx(-2);
return;
}
switch (sort_bool) {
case 1:
for (vector<queue<int>>::iterator i = temp_l.begin(); i != temp_l.end() - 1;) {
if (flight_totalnumber[i->back()].finish_time -
flight_totalnumber[i->front()].start_time >
flight_totalnumber[(i + 1)->back()].finish_time -
flight_totalnumber[(i + 1)->front()].start_time) {
i = temp_l.erase(i);
}
else {
i = temp_l.erase(i + 1);
i--;
}
}
temp_q = temp_l[0];
while (!temp_q.empty()) {
print_flight_data(flight_totalnumber[temp_q.front()]);
temp_q.pop();
}
break;
case 2: {
int t1(0);
int t2(0);
temp_q = temp_l[0];
while (!temp_q.empty()) {
t1 += flight_totalnumber[temp_q.front()].price;
temp_q.pop();
}
for (vector<queue<int>>::iterator i = temp_l.begin(); i != temp_l.end() - 1;) {
t2 = 0;
temp_q = *(i + 1);
while (!temp_q.empty()) {
t2 += flight_totalnumber[temp_q.front()].price;
temp_q.pop();
}
if (t1 > t2) {
i = temp_l.erase(i);
t1 = t2;
}
else {
i = temp_l.erase(i + 1);
i--;
}
}
temp_q = temp_l[0];
while (!temp_q.empty()) {
print_flight_data(flight_totalnumber[temp_q.front()]);
temp_q.pop();
}
break;
}
default:
print_lzx(-2);
return;
}
print_lzx(-1);
}
#endif /* Airplane_System_hpp */