#include <iostream>
#include <time.h>
#include <list>
using namespace std;
void main() {
list<int> value;
srand(time(NULL));
for (int i = 0; i < 10; i++) {
value.push_back(rand() % 100);
}
value.sort();
for (auto& e : value)
cout << e << " ";
cout << endl;
}
#include <iostream>
#include <vector>
using namespace std;
void main() {
vector<int> score(5);
for (int i = 0; i < score.size(); i++) {
cout << "성적입력 : ";
cin >> score[i];
}
int hightest = score[0];
for (int i = 0; i < score.size(); i++) {
if (score[i] > hightest)
hightest = score[i];
}
cout << "최고 성적 " << hightest << "이다." << endl;
}
#include <iostream>
#include <vector>
using namespace std;
void main() {
vector<int> score(5);
int value;
while (true)
{
cout << "성적입력 : ";
cin >> value;
if (value < 0) break;
score.push_back(value);
}
int hightest = score[0];
for (int i = 0; i < score.size(); i++) {
if (score[i] > hightest)
hightest = score[i];
}
cout << "최고 성적 " << hightest << "이다." << endl;
}
#include <iostream>
#include <vector>
using namespace std;
void main() {
vector<int> score(5);
int value;
while (true)
{
cout << "성적입력 : ";
cin >> value;
if (value < 0) break;
score.push_back(value);
}
int hightest = score[0];
vector<int>::iterator it;
for (it = score.begin(); it < score.end(); it++) {
if (*it > hightest)
hightest = *it;
}
cout << "최고 성적 " << hightest << "이다." << endl;
}
#include <iostream> // 14년 이전 버젼
#include <vector>
using namespace std;
void main() {
vector<int> v;
v.push_back(32);
v.push_back(12);
v.push_back(24);
v.pop_back();
v.push_back(100);
vector<int>::iterator it;
for (it = v.begin(); it != v.end(); it++)
cout << *it << endl;
}
#include <iostream> // 바뀐건 이거 하나 ( auto )
#include <vector>
using namespace std;
void main() {
vector<int> v;
v.push_back(32);
v.push_back(12);
v.push_back(24);
v.pop_back();
v.push_back(100);
// vector<int>::iterator it;
for (auto it = v.begin(); it != v.end(); it++)
cout << *it << endl;
}
#include <iostream>
#include <vector>
using namespace std;
void main() {
vector<int> v;
v.push_back(32);
v.push_back(12);
v.push_back(24);
v.pop_back();
v.push_back(100);
// vector<int>::iterator it;
for (auto& it:v)
cout << it << endl;
}
#include <iostream>
#include <deque>
using namespace std;
void main() {
deque<int> dq = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
dq.pop_front();
dq.pop_back();
dq.push_front(100);
dq.push_back(100);
for (auto& it : dq)
cout << it << endl;
}
#include <iostream>
#include <deque>
using namespace std;
void main() {
deque<string> dq = { "naver", "google", "yahoo" };
dq.pop_front();
dq.pop_back();
dq.push_front("infinity");
dq.push_back("intel");
for (auto& it : dq)
cout << it << endl;
}
#include <iostream>
#include <list>
using namespace std;
void main() {
list<int> li = {10, 20, 30, 40};
// list<int>::iterator it; // 가능하지만 예전 방식
auto it = li.begin();
it++;
it++;
li.insert(it, 25);
li.push_back(100);
li.sort();
for (auto& it : li)
cout << it << endl;
}
#include <iostream>
#include <map>
using namespace std;
void main() {
string word;
map<string, string> dic;
dic["boy"] = "소년";
dic["school"] = "학교";
dic["office"] = "사무실";
dic["house"] = "집";
cout << "단어를 입력하시오 :";
cin >> word;
string meaning = dic[word];
if (meaning != "")
cout << word << "의미는" << meaning << "이다." << endl;
}
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void printEven(int n) {
if (n % 2 == 0)
cout << n << " ";
}
void main() {
vector<int> v = { 1, 2, 3, 4, 5 };
for_each(v.begin(), v.end(), printEven);
cout << endl;
}
#include <iostream>
using namespace std;
int sum(int x, int y) {
cout << "외부 함수" << endl;
return x + y;
}
void main() {
auto sum = [](int x, int y)
{
cout << "람다 함수" << endl;
return x + y;
};
cout << sum(1, 2) << endl;
}