More actions
imported>Unknown No edit summary |
(Repair batch-0005 pages from live compare) |
||
| Line 11: | Line 11: | ||
void main() | void main() | ||
{ | { | ||
student st | student st[5]; | ||
st | st[0].name = "nj"; | ||
st | st[0].score = 76; | ||
st | st[1].name = "jk"; | ||
st | st[1].score = 66; | ||
st | st[2].name = "hj"; | ||
st | st[2].score = 78; | ||
st | st[3].name = "gh"; | ||
st | st[3].score = 73; | ||
vector<student> sp; | vector<student> sp; | ||
sp.push_back(st | sp.push_back(st[1]); | ||
sp.push_back(st | sp.push_back(st[2]); | ||
sp.push_back(st | sp.push_back(st[3]); | ||
sp.push_back(st | sp.push_back(st[4]); | ||
sort(sp.begin(), sp.end(), compare); | sort(sp.begin(), sp.end(), compare); | ||
| Line 54: | Line 54: | ||
자다가..배꼈는데..에러가있다..난감하다.. | 자다가..배꼈는데..에러가있다..난감하다.. | ||
---- | ---- | ||
STL실습, 데블스캠프2004/목요일 | |||
Latest revision as of 00:44, 27 March 2026
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
struct student{string name; int score;};
bool compare(student a, student b);
bool compare2(student a, student b);
void main()
{
student st[5];
st[0].name = "nj";
st[0].score = 76;
st[1].name = "jk";
st[1].score = 66;
st[2].name = "hj";
st[2].score = 78;
st[3].name = "gh";
st[3].score = 73;
vector<student> sp;
sp.push_back(st[1]);
sp.push_back(st[2]);
sp.push_back(st[3]);
sp.push_back(st[4]);
sort(sp.begin(), sp.end(), compare);
for(vector<student>::iterator i= sp.begin();i!=sp.end(); i++)
cout << i->name <<"\t"<< i->score << endl;
cout << "-------------------------------------"<<endl;
sort(sp.begin(),sp.end(),compare2);
for(i=sp.begin();i<sp.end();i++)
cout << i->name<<"\t"<<i->score<< endl;
}
bool compare(student a, student b);
{
return a.name < b.name;
}
bool compare2(student a, student b);
{
return a.score < b.score;
}
자다가..배꼈는데..에러가있다..난감하다..
STL실습, 데블스캠프2004/목요일