-
Notifications
You must be signed in to change notification settings - Fork 0
/
fxxk.cc
73 lines (65 loc) · 1.37 KB
/
fxxk.cc
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
namespace Fxxk {
static std::string base = "abc";
static std::string str = "";
class Fxxk {
private:
bool canMove;
public:
friend class Body;
friend class Animal;
friend class Plant;
virtual void say() = 0;
};
class Animal : virtual public Fxxk {
public:
Animal() { canMove = true; }
void say() { std::cout << "Animal: Fxxk!" << std::endl; }
};
class Plant : virtual public Fxxk {
public:
Plant() { canMove = false; }
void say() { std::cout << "Plant: Fxxk!" << std::endl; }
};
class Body : public Animal, public Plant {
public:
Body(bool cm) { canMove = cm; }
Body(Fxxk& fxxk) { canMove = fxxk.canMove; }
void say() {
if (canMove)
Animal::say();
else
Plant::say();
}
};
static bool str2bool(std::string s) {
if (s == "true") {
return true;
} else if (s == "false") {
return false;
}
throw std::exception();
}
static void exec() {
std::cout << "Hi, can you move? (true or false)" << std::endl;
std::string flag;
std::cin >> flag;
try {
auto body = Body(str2bool(flag));
body.say();
} catch (const std::exception& e) {
std::cout << "YOU MISSED FXXK" << std::endl;
}
}
static bool handler(char ch) {
str += ch;
int sz = str.size();
if (str[sz - 1] != base[sz - 1]) {
str = "";
} else if (str == base) {
str = "";
exec();
return true;
}
return false;
}
} // namespace Fxxk