-
Notifications
You must be signed in to change notification settings - Fork 0
/
63A- Sinking Ship.cpp
77 lines (56 loc) · 1.24 KB
/
63A- Sinking Ship.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
#include <bits/stdc++.h>
using namespace std;
pair<string,string>p[100];
string rats[100],WandC[100],captin[100],man[100];
int Rcounter,WCcounter,Ccounter,Mcounter;
int search(string s){
if(s=="rat")
return 1;
if(s=="woman" || s=="child")
return 2;
if(s=="man")
return 3;
if(s=="captain")
return 4;
}
void solve(){
for(int i=0;i<Rcounter;++i)
cout<<rats[i]<<endl;
for(int i=0;i<WCcounter;++i)
cout<<WandC[i]<<endl;
for(int i=0;i<Mcounter;++i)
cout<<man[i]<<endl;
for(int i=0;i<Ccounter;++i)
cout<<captin[i]<<endl;
}
int main()
{
int n,i=0;
cin>>n;
int m=n;
while(m--){
string s1,s2;
cin>>s1>>s2;
p[i].first=s1;
p[i++].second=s2;
}
int j=0;
for( i=0;i<n;++i){
int x=search(p[i].second);
//cout<<x<<endl;;
if(x==1){
rats[Rcounter++]=p[i].first;
}
else if(x==2){
WandC[WCcounter++]=p[i].first;
}
else if(x==3){
man[Mcounter++]=p[i].first;
}
else if(x==4){
captin[Ccounter++]=p[i].first;
}
}
solve();
return 0;
}