More actions
imported>Unknown No edit summary |
(Repair batch-0005 pages from live compare) |
||
| Line 50: | Line 50: | ||
for(int j=0;j<2;j++) | for(int j=0;j<2;j++) | ||
{ | { | ||
cout << vec | cout << vec[j].score << " "; | ||
} | } | ||
cout << endl; | cout << endl; | ||
| Line 62: | Line 62: | ||
} | } | ||
---- | ---- | ||
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;
};
bool compare(student a, student b);
int main()
{
student DarkLJY;
student B;
student C;
student D;
DarkLJY.name = "juyoung";
B.name = "gogogo";
C.name = "hahaha";
D.name = "good";
DarkLJY.score = 50;
B.score = 70;
C.score = 80;
D.score =90;
vector < student > vec;
vec.push_back(DarkLJY);
vec.push_back(B);
vec.push_back(C);
vec.push_back(D);
vector < student > vec;
vec.push_back(DarkLJY);
vec.push_back(B);
sort(vec.begin(),vec.end(),compare);
for(int j=0;j<2;j++)
{
cout << vec[j].score << " ";
}
cout << endl;
return 0;
}
bool compare(student a, student b)
{
return a.score > b.score ; // 부등호의 방향에 따라 오름차순 내림차순 결정
}
STL실습, 데블스캠프2004/목요일