Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

벡터/곽세환,조재화: Difference between revisions

From ZeroWiki
imported>Unknown
No edit summary
 
(Repair batch-0005 pages from live compare)
 
Line 48: Line 48:
  /*for(int i=0; i<vec.size(); i++)
  /*for(int i=0; i<vec.size(); i++)
  {
  {
  cout<< (student)vec[i].name << endl;
  cout<< (student)vec[i].name << endl;
  }*/
  }*/
  }
  }
Line 60: Line 60:
  }
  }
----
----
[[STL실습]], [[데블스캠프2004/목요일]]
STL실습, 데블스캠프2004/목요일
 

Latest revision as of 00:44, 27 March 2026

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

struct student {
	string name;
	int score;
};

bool compare(student a, student b);
bool compareName(student a, student b);
void main()
{
	vector<student> vec;
	vector<student>::iterator i;
	student a, b, c, d, e;
	a.name = "재화";
	a.score = 100;
	b.name = "세환";
	b.score = 40;
	c.name = "김군";
	c.score = 30;
	d.name = "이군";
	d.score = 20;
	e.name = "박양";
	e.score = 50;
	
	//cout << a.score;

	vec.push_back(a);
	vec.push_back(b);
	vec.push_back(c);
	vec.push_back(d);
	vec.push_back(e);
	
	sort(vec.begin(), vec.end(), compare);
	for (i = vec.begin(); i < vec.end(); i++)
		cout << i->name << " " << i->score << endl;
	cout<<"------------------------------"<<endl;
	sort(vec.begin(), vec.end(), compareName);
	for (i = vec.begin(); i < vec.end(); i++)
		cout << i->name << " " << i->score << endl;
	
	
	/*for(int i=0; i<vec.size(); i++)
	{
		cout<< (student)vec[i].name << endl;
	}*/
}
bool compare(student a, student b)
{
	return a.name < b.name;
}
bool compareName(student a, student b)
{
	return a.score < b.score;
}

STL실습, 데블스캠프2004/목요일