-
Notifications
You must be signed in to change notification settings - Fork 0
/
musicyourway.cpp
63 lines (51 loc) · 1.3 KB
/
musicyourway.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
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <unordered_map>
using namespace std;
vector<vector<string> > v;
vector<string> att;
unordered_map<string, int> order;
int main () {
int counts = 0, n;
string attributes, token;
getline(cin, attributes);
istringstream iss(attributes);
while(iss >> token) {
order[token] = counts++;
att.push_back(token);
}
cin >> n;
v.assign(n, vector<string>());
for (int i = 0; i < n; i++) {
for (int j = 0; j < counts; j++) {
string in;
cin >> in;
v[i].push_back(in);
}
}
cin >> n;
while (n--) {
string in;
int index;
cin >> in;
index = order[in];
for (auto &it : v)
swap(it[0], it[index]);
stable_sort(v.begin(), v.end(), [](vector<string> a, vector<string> b) {
return a[0] < b[0];
});
for (auto &it : v)
swap(it[0], it[index]);
for (auto &it : att)
cout << it << " ";
cout << endl;
for (auto &it : v) {
for (auto &itt : it) cout << itt << " ";
cout << endl;
}
cout << endl;
}
return 0;
}