More actions
imported>Unknown No edit summary |
(Repair batch-0005 pages from live compare) |
||
| Line 25: | Line 25: | ||
void main() | void main() | ||
{ | { | ||
student students | student students[5] = { | ||
student("황선홍",94), | student("황선홍",94), | ||
student("홍명보",95), | student("홍명보",95), | ||
| Line 36: | Line 36: | ||
for(int i=0; i<5; i++) | for(int i=0; i<5; i++) | ||
vector1.push_back(students | vector1.push_back(students[i]); | ||
sort(vector1.begin(), vector1.end(), comp_score); | sort(vector1.begin(), vector1.end(), comp_score); | ||
for(i=0; i<5; i++) | for(i=0; i<5; i++) | ||
cout << vector1 | cout << vector1[i].score << endl ; | ||
sort(vector1.begin(), vector1.end(), comp_name); | sort(vector1.begin(), vector1.end(), comp_name); | ||
| Line 60: | Line 60: | ||
} | } | ||
---- | ---- | ||
STL실습, 데블스캠프2004/목요일 | |||
Latest revision as of 00:44, 27 March 2026
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct student{
string name;
int score;
student()
{
}
student(string aName, int aScore) // 생성자 ?? !!
{
name = aName;
score = aScore;
}
};
bool comp_score(student a, student b);
bool comp_name(student a, student b);
void main()
{
student students[5] = {
student("황선홍",94),
student("홍명보",95),
student("김태영",93),
student("최용수",87),
student("안정환",98),
};
vector<student> vector1;
for(int i=0; i<5; i++)
vector1.push_back(students[i]);
sort(vector1.begin(), vector1.end(), comp_score);
for(i=0; i<5; i++)
cout << vector1[i].score << endl ;
sort(vector1.begin(), vector1.end(), comp_name);
for(vector<student>::iterator j=vector1.begin(); j<vector1.end(); j++)
cout << (*j).name << endl ;
}
bool comp_score(student a, student b)
{
return a.score < b.score;
}
bool comp_name(student a, student b)
{
return a.name < b.name;
}
STL실습, 데블스캠프2004/목요일