#include <iostream>
#include <map>
#include <string>
// Custom comparator for pair<int, string>
struct PairCompare {
bool operator()(const std::pair<int, std::string>& lhs,
const std::pair<int, std::string>& rhs) const {
if (lhs.first != rhs.first)
return lhs.first < rhs.first;
return lhs.second < rhs.second;
}
};
int main() {
std::map<std::pair<int, std::string>, double, PairCompare> scores;
scores[{1, "Alice"}] = 95.5;
scores[{2, "Bob"}] = 89.0;
scores[{1, "Charlie"}] = 91.5;
scores[{3, "David"}] = 87.5;
for (const auto& entry : scores) {
std::cout << "Student ID: " << entry.first.first
<< ", Name: " << entry.first.second
<< ", Score: " << entry.second << std::endl;
}
// Finding a specific entry
auto it = scores.find({1, "Alice"});
if (it != scores.end()) {
std::cout << "\nFound: " << it->first.second
<< " (ID: " << it->first.first
<< ") with score " << it->second << std::endl;
}
return 0;
}