forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmusicyourway.cpp
71 lines (61 loc) · 1.47 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
64
65
66
67
68
69
70
71
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int index;
bool compare(vector<string> lhs, vector<string> rhs) {
return lhs[index] < rhs[index];
}
int main() {
string s;
getline(cin, s);
// Get a vector of all the categories
vector<string> split;
split.push_back("");
for(auto i : s) {
if(i == ' ') {
split.push_back("");
}
else {
split.back().push_back(i);
}
}
// Take in all the songs
int num_songs;
cin >> num_songs;
vector<vector<string>> v;
for(int i = 0; i < num_songs; i++) {
vector<string> song;
for(int j = 0; j < split.size(); j++) {
string temp;
cin >> temp;
song.push_back(temp);
}
v.push_back(song);
}
// Sort every time
int num_queries;
cin >> num_queries;
for(int i = 0; i < num_queries; i++) {
string query;
cin >> query;
// Sort on the index
for(int i = 0; i < split.size(); i++) {
if(split[i] == query) {
index = i;
}
}
stable_sort(v.begin(), v.end(), compare);
// Print the list of songs
cout << s << endl;
for(auto song : v) {
for(auto property : song) {
cout << property << " ";
}
cout << endl;
}
if(i != num_queries - 1) {
cout << endl;
}
}
}