U E D R , A S I H C RSS

벡터/임영동

~cpp 
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
struct student{
 string name;
 int score;
 student(string n, int s)
 {
  name=n;
  score=s;
 }
};
bool compare(student person1, student person2)
{
 return person1.score>person2.score;
}
int main()
{
 student student1("Kim", 80);
 student student2("Park", 84);
 student student3("Choi", 82);
 vector< student > vec;
 vec.push_back(student1);
 vec.push_back(student2);
 vec.push_back(student3);
 sort(vec.begin(), vec.end(), compare);

 for(vector<student>::iterator i=vec.begin();i!=vec.end();i++)
 {
  cout<<(*i).name<<" "<<(*i).score<<endl;
 }

 return 0;
}


STL실습,블스캠프2004/목요일
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:36
Processing time 0.0123 sec