~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; }