-
Notifications
You must be signed in to change notification settings - Fork 0
/
prob_00939.cpp
66 lines (60 loc) · 1.77 KB
/
prob_00939.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
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <climits>
#include <list>
#include <forward_list>
#define rep(i,a,b) for(i=a;i<b;++i)
#define vectIter(vect) for(auto &val: vect)
#define mapIter(map_) for(auto &val_: map_)
#define gc getchar_unlocked
using namespace std;
int main(){
int i,j,k,n;
string str1, str2;
scanf("%d",&n);
map<string, string> person_disease;
map<string, vector<string> > person_person;
while(n--){
cin >> str1 >> str2;
if(str2=="non-existent" || str2=="recessive" || str2=="dominant")
person_disease[str1]= str2;
else{
if(person_person.find(str2)==person_person.end())
person_person[str2]= vector<string>{str1};
else person_person[str2].push_back(str1);
}
}
while(person_person.size()){
for(auto iter= person_person.begin(); iter!= person_person.end();){
string parent1= iter->second[0];
string parent2= iter->second[1];
string name= iter->first;
// cout << parent1 <<" " << parent2 <<endl;
if(person_disease.find(parent1)!= person_disease.end() &&
person_disease.find(parent2)!= person_disease.end()){
// cout <<"came here\n";
unsigned char p1_d= person_disease[parent1][0];
unsigned char p2_d= person_disease[parent2][0];
if((p1_d!='n' && p2_d!='n') || (p1_d=='d' || p2_d=='d')){
if( (p1_d+ p2_d == ('d'<<1)) || (p1_d+p2_d== 'r'+'d'))
person_disease[name]="dominant";
else person_disease[name]="recessive";
}else person_disease[name]="non-existent";
iter= person_person.erase(iter);
}else ++iter;
}
}
for(auto& val: person_disease)
cout << val.first <<" "<< val.second <<endl;
}