~cpp #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; struct student { string name; int score; }; bool compareWithName(student a, student b); bool compareWithScore(student a, student b); int main() { student stu[5]; stu[0].name = ""; stu[0].score = 1; stu[1].name = ""; stu[1].score = 10; stu[2].name = "곽"; stu[2].score = 6; stu[3].name = ""; stu[3].score = 4; stu[4].name = ""; stu[4].score = 5; vector<student> ss; ss.push_back(stu[0]); ss.push_back(stu[1]); ss.push_back(stu[2]); ss.push_back(stu[3]); ss.push_back(stu[4]); sort(ss.begin(), ss.end(), compareWithName); for (vector<student>::iterator i = ss.begin(); i < ss.end(); i++) // cout << (*i).name << "\t" << (*i).score << endl; cout << endl; sort(ss.begin(), ss.end(), compareWithScore); for (i = ss.begin(); i < ss.end(); i++) // cout << (*i).name << "\t" << (*i).score << endl; return 0; } bool compareWithName(student a, student b) { return a.name < b.name; } bool compareWithScore(student a, student b) { return a.score < b.score; }