-
Notifications
You must be signed in to change notification settings - Fork 0
/
main24a2.cpp
97 lines (86 loc) · 2.48 KB
/
main24a2.cpp
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
//
// 234218 Data Structures 1.
// Semester: 2023B (spring).
// Wet Exercise #1.
//
// Recommended TAB size to view this file: 8.
//
// The following main file is necessary to link and run your code.
// This file is READ ONLY: even if you submit something else, the compiler ..
// .. WILL use our file.
//
#include "olympics24a2.h"
#include <string>
#include <iostream>
using namespace std;
void print(string cmd, StatusType res);
void print(string cmd, output_t<int> res);
int main()
{
int d1, d2;
// Init
olympics_t *obj = new olympics_t();
// Execute all commands in file
string op;
while (cin >> op)
{
if (!op.compare("add_team")) {
cin >> d1;
print(op, obj->add_team(d1));
} else if (!op.compare("remove_team")) {
cin >> d1;
print(op, obj->remove_team(d1));
} else if (!op.compare("add_player")) {
cin >> d1 >> d2;
print(op, obj->add_player(d1, d2));
} else if (!op.compare("remove_newest_player")) {
cin >> d1;
print(op, obj->remove_newest_player(d1));
} else if (!op.compare("play_match")) {
cin >> d1 >> d2;
print(op, obj->play_match(d1, d2));
} else if (!op.compare("num_wins_for_team")) {
cin >> d1;
print(op, obj->num_wins_for_team(d1));
} else if (!op.compare("get_highest_ranked_team")) {
print(op, obj->get_highest_ranked_team());
} else if (!op.compare("unite_teams")) {
cin >> d1 >> d2;
print(op, obj->unite_teams(d1, d2));
} else if (!op.compare("play_tournament")) {
cin >> d1 >> d2;
print(op, obj->play_tournament(d1, d2));
} else {
cout << "Unknown command: " << op << endl;
return -1;
}
// Verify no faults
if (cin.fail()){
cout << "Invalid input format" << endl;
return -1;
}
}
// Quit
delete obj;
return 0;
}
// Helpers
static const char *StatusTypeStr[] =
{
"SUCCESS",
"ALLOCATION_ERROR",
"INVALID_INPUT",
"FAILURE"
};
void print(string cmd, StatusType res)
{
cout << cmd << ": " << StatusTypeStr[(int) res] << endl;
}
void print(string cmd, output_t<int> res)
{
if (res.status() == StatusType::SUCCESS) {
cout << cmd << ": " << StatusTypeStr[(int) res.status()] << ", " << res.ans() << endl;
} else {
cout << cmd << ": " << StatusTypeStr[(int) res.status()] << endl;
}
}