#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { //정렬
//return a > b;
if (a > b)
return true;
else
return false;
}
void vectorPrac(){ //벡터
vector<int> v;
v.push_back(0);
v.push_back(1);
v.push_back(-1);
sort(v.begin(), v.end(), cmp); //정렬 함수 사용자 정의
for (int i = 0; i < v.size(); i++) {
cout << v[i] << ' ';
}
cout << '\n';
v.erase(v.begin() + 1); //특정 인덱스 원소 제거
for (int i = 0; i < v.size(); i++) {
cout << v[i] << ' ';
}
vector<string> strv;
strv.push_back("abc\n");
cout << strv[0];
string a = "abcdef";
string subs = a.substr(1, 3); //1번째부터 시작해서 길이 3만큼
cout << subs << '\n';
}
void stackPrac(){ //스택
stack<int> stk;
stk.push(1);
stk.pop();
stk.push(5);
stk.push(4);
cout << "스택크기 = " << stk.size() << '\n';
while(!stk.empty()){
cout << stk.top() << ' ';
stk.pop();
}
cout << '\n';
}
void queuePrac(){ //큐
queue<int> q;
q.push(1);
q.push(2);
cout << "큐 크기 = " << q.size() << '\n';
while(!q.empty()){
cout << q.front() << ' ';
q.pop();
}
cout << '\n';
}
void mapPrac(){
map<string, int> mp;
mp.insert({"abc", 1});
mp.insert({"def", 2});
mp.insert({"abc", 3}); //이미 존재하는 key에 대해서 insert 하면 무시된다
mp["abc"] = 3; //하지만 이렇게 수정하면 반영된다.
for(auto itr = mp.begin() ; itr != mp.end() ; itr++){
cout << itr->first << " " << itr->second << '\n';
cout << itr->first << " " << mp[itr->first] << '\n';
}
cout << "맵 크기 = " << mp.size() << '\n';
}
void setPrac(){
vector<int> v = {4,4,4,5,1,1,1,2,3};
for(int i = 0 ; i < v.size() ; i++){
cout << v[i] << ' ';
}
cout << '\n';
set<int> st;
for(int i = 0 ; i < v.size() ; i++){
st.insert(v[i]);
}
for(auto itr = st.begin() ; itr != st.end() ; itr++){
cout << *itr << ' ';
}
cout << '\n';
set<int, greater<int> > bigSt;
for(int i = 0 ; i < v.size() ; i++){
bigSt.insert(v[i]);
}
for(auto itr = bigSt.begin() ; itr != bigSt.end() ; itr++){
cout << *itr << ' ';
}
cout << '\n';
}
void priority_queuePrac(){
priority_queue<int, vector<int>, less<int> > pq; //내림차순으로 나오는
pq.push(9);
pq.push(1);
pq.push(4);
pq.push(5);
pq.push(2);
while(!pq.empty()){
cout << pq.top();
pq.pop();
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
vectorPrac();
stackPrac();
queuePrac();
mapPrac();
setPrac();
priority_queuePrac();
}