-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
140 lines (137 loc) · 3.82 KB
/
main.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
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
#include<iostream>
#include<vector>
#include <map>
using namespace std;
int flag=0;
map<int,char> red_map;
map<int,char> blue_map;
class Robot{
private:
int blood;
int heat;
char type;
public:
char team;
int num;
Robot(int robot_num, char robot_team){
team=robot_team;
num=robot_num;
if(robot_team == 'R') type=red_map[robot_num];
else if(robot_team == 'B') type=blue_map[robot_num];
if(type=='B'){
blood=100;
heat=0;
return;
}else if(type=='S'||type=='Y'||type=='G'){
blood=200;
heat=0;
return;
}
};
void show();
void damage(int injury);
void overheat(int bullet);
};
void Robot::overheat(int bullet){
if(type=='B'||type=='S'){
heat=heat+15*bullet;
if(type=='B' && heat>=200){
blood=0;
heat=0;
}else if(type=='S' && heat>=300){
blood=0;
heat=0;
}
}else if(type=='Y'){
heat=heat+30*bullet;
if(heat>=300){
blood=0;
heat=0;
}
}else return;
}
void Robot::damage(int injury){
blood=blood-injury;
if(blood<=0){
blood=0;
heat=0;
}
}
vector<Robot> vector_robot;
void Robot::show(){
cout<<"Type: "<<type<<" Number: "<<num<<" Blood: "<<blood<<" Heat: "<<heat<<endl;
}
void error(){
cout<<"The input is not standardized!"<<endl;
flag=1;
}
int test(int test_team,int test_num){
int test = 0;
for(auto & p : vector_robot){
if(p.Robot::team == test_team){
if(p.Robot::num == test_num){
test++;
}
}
}
return test;
}
int main(){
char tmp_team,tmp_type;
int tmp_num,tmp_injury,tmp_bullet;
char cmd[4]="000";
while(flag==0){
cin>>cmd;
if((cmd[0]!='A'&&cmd[0]!='F'&&cmd[0]!='H'&&cmd[0]!='E')||cin.fail()) error();
else if(cmd[0]=='A'){
cin>>tmp_team;
cin>>tmp_type;
cin>>tmp_num;
if((tmp_team!='R'&&tmp_team!='B')||(tmp_type!='B'&&tmp_type!='S'&&tmp_type!='Y'&&tmp_type!='G')||tmp_num<=0||cin.fail()) error();
if(tmp_team=='R'){
if(test(tmp_team,tmp_num)==0) red_map.insert(pair<int,char>(tmp_num,tmp_type));
else error();
} else if(tmp_team=='B'){
if(test(tmp_team,tmp_num)==0) blue_map.insert(pair<int,char>(tmp_num,tmp_type));
else error();
}
vector_robot.emplace_back(tmp_num, tmp_team);
}else if(cmd[0]=='F'){
cin>>tmp_team;
cin>>tmp_num;
cin>>tmp_injury;
if((tmp_team!='R'&&tmp_team!='B') || test(tmp_team,tmp_num)==0 || cin.fail()) error();
for(auto & p : vector_robot){
if(p.Robot::team == tmp_team){
if(p.Robot::num == tmp_num){
p.damage(tmp_injury);
break;
}
}
}
}else if(cmd[0]=='H'){
cin>>tmp_team;
cin>>tmp_num;
cin>>tmp_bullet;
if((tmp_team!='R'&&tmp_team!='B') || test(tmp_team,tmp_num)==0 || cin.fail()) error();
for(auto & p : vector_robot){
if(p.Robot::num == tmp_num){
if(p.Robot::team == tmp_team){
p.overheat(tmp_bullet);
break;
}
}
}
}else if(cmd[0]=='E'){
cout<<"Red team:"<<endl;
for(auto & p :vector_robot){
if(p.Robot::team == 'R') p.show();
}
cout<<"Blue team:"<<endl;
for(auto & p :vector_robot){
if(p.Robot::team == 'B') p.show();
}
flag=1;
}
}
}