error: passing ‘const Student’ as ‘this’ argument discards qualifiers
Не понимаю, в чём проблема с сортировкой.
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
struct Student {
string name;
string s_name;
int d;
int m;
int y;
int mark;
vector<string> pref;
};
bool Comp(
const Student& a,
const Student& b){
if (a.s_name != b.s_name) {
return a.s_name < b.s_name;
} else if (a.name != b.name) {
return a.name < b.name;
} else if (a.y != b.y) {
return a.y < b.y;
} else if (a.m != b.m) {
return a.m < b.m;
} else {
return a.d < b.d;
}
}
int main() {
int n;
cin >> n;
map<string, int> univer;
map<string, vector<Student>> st_in_un;
int k;
cin >> k;
vector<Student> st(k);
// мой код
for (const auto& s : st) {
for (const auto& u : s.pref) {
if (univer[u] > 0) {
univer[u]--;
st_in_un[u].push_back(s);
break;
}
}
}
for (const auto& [key, val] : st_in_un) {
cout << key;
sort(val.begin(), val.end(), Comp);
for (const auto& s : val) {
cout << '\t' << s.name << " " << s.s_name;
}
cout << '\n';
}
return 0;
}