-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5122.cpp
97 lines (84 loc) · 1.79 KB
/
5122.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
#include <iostream>
#include <string>
const int SEAT_NUM = 10;
class Seat {
private:
static int count;
protected:
void acquire(std::string name = "seat") {
if (count < SEAT_NUM)
{
++ count;
std::cout << name << ": allocated "
<< count << "/" << SEAT_NUM << std::endl;
}
else
{
std::cout << "out of memory" << std::endl;
}
}
void release()
{
if (count > 0)
{
std::cout << "release: " << count
<< "/" << SEAT_NUM << std::endl;
-- count;
}
}
public:
virtual ~Seat() {release();}
};
int Seat::count = 0;
class Boy : public Seat {
private:
bool flag;
std::string name;
public:
Boy():flag(false),name("boy") {
}
virtual ~Boy() {
}
void giao() {
flag = true;
Seat::acquire(name);
}
};
Boy *b[26];
int op[100], op2[100];
int main(int argc, char *argv[])
{
int round_;
int n;
std::cin >> round_ >> n;
for (int i = 0; i < n; ++i)
{
char c;
std::cin >> op[i] >> c;
op2[i] = c - 'a';
}
for (int i = 0; i < 26; ++i)
{
b[i] = NULL;
}
for (int r = 0; r < round_; ++r)
{
std::cout << "#round: " << r << std::endl;
for (int i = 0; i < n; ++i)
{
int d = op2[i];
delete b[d];
b[d] = NULL;
if (op[i] == 0)
{
b[d] = new Boy();
b[d]->giao();
}
}
}
for (int i = 0; i < 26; ++i)
{
delete b[i];
}
return 0;
}