-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathccc00s2p1.cpp
More file actions
56 lines (56 loc) · 1.89 KB
/
ccc00s2p1.cpp
File metadata and controls
56 lines (56 loc) · 1.89 KB
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
//maps, vectors, pointers
/*In this problem, you will write a program to find the minimal solution to a set of set inequalities.
A set inequality has the format X contains S
where X may be any set name and S may be a set name or set element. If S is a set name the inequality means
that X is a superset or equal to S. If S is an element the inequality means that X contains S. Sets are named A-Z
and contain elements from a-z.*/
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
int N;
map<char,vector<char>> storage;
int main()
{
cin>>N;
char instr[N][2];
string cont;
int val;
for (int i=0;i<N;i++){
cin>>instr[i][0]>>cont>>instr[i][1];
if (storage.find(instr[i][0])==storage.end()){
storage[instr[i][0]];
}
}
for (int i=0;i<N;i++){
for (int j=0;j<N;j++){
val = instr[j][1];
if (65<=val && val<=90){
for (int k=0;k<storage[instr[j][1]].size();k++){
if (find(storage[instr[j][0]].begin(),storage[instr[j][0]].end(),storage[instr[j][1]][k])==storage[instr[j][0]].end()){
storage[instr[j][0]].push_back(storage[instr[j][1]][k]);
}
}
}
else{
if (find(storage[instr[j][0]].begin(),storage[instr[j][0]].end(),instr[j][1])==storage[instr[j][0]].end()){
storage[instr[j][0]].push_back(instr[j][1]);
}
}
}
}
map<char,vector<char>>::iterator it;
for (it = storage.begin();it!=storage.end();it++){
cout<<it->first<<" = ";
cout<<"{";
sort(it->second.begin(),it->second.end());
for (int i=0;i<it->second.size();i++){
if (i!=0){
cout<<",";
}
cout<<it->second[i];
}
cout<<"}"<<endl;
}
}