-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11_2_TestSetContainer.cpp
More file actions
93 lines (88 loc) · 1.85 KB
/
11_2_TestSetContainer.cpp
File metadata and controls
93 lines (88 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include<set>
#include <string>
#include<iostream>
#include <Windows.h>
template <typename T, typename C>
void print(const std::set<T, C> &s)
{
std::cout << "[ ";
for (typename std::set<T>::const_iterator iter = s.cbegin(); iter != s.cend(); ++iter)
{
std::cout << (*iter) << " ";
}
std::cout << "]\n";
}
template <typename T>
void answer_is_elem(const std::set<T>& s, T val)
{
if (s.find(val) != s.end())
{
std::cout << "Yes\n";
}
else
{
std::cout << "No\n";
}
}
class Todo
{
int priority;
std::string desc;
public:
Todo(int _priority, std::string _desc):priority(_priority), desc(_desc){}
//bool operator<(const Todo& td) const
//{
// if (priority == td.priority)
// {
// return desc < td.desc;
// }
// // 숫자가 낮은 것이 중요도가 더 높기 때문
// return priority > td.priority;
//}
friend struct TodoCmp;
friend std::ostream& operator<< (std::ostream& o, const Todo& td);
};
struct TodoCmp
{// Functor
bool operator()(const Todo& a, const Todo& b) const
{
if (a.priority == b.priority)
{
return a.desc < b.desc;
}
return a.priority > b.priority;
}
};
std::ostream& operator<< (std::ostream& o, const Todo& td)
{
o << "[중요도: " << td.priority << "] " << td.desc << std::endl;
return o;
}
void test_set()
{
set<int> s;
for (int i = 5; i >= 1; --i)
{
s.insert(i * 10);
}
print(s);
cout << "Is 20 element of s?: ";
answer_is_elem(s, 20);
cout << "Is 25 element of s?: ";
answer_is_elem(s, 25);
set<Todo, TodoCmp>todos;
todos.insert(Todo(1, "play basketball"));
todos.insert(Todo(2, "do math assignment"));
todos.insert(Todo(1, "programming project"));
todos.insert(Todo(3, "meet friends"));
todos.insert(Todo(2, "watch a movie"));
print(todos);
todos.erase(todos.find(Todo(2, "do math assignment")));
print(todos);
}
using namespace std;
int main(void)
{
SetConsoleOutputCP(CP_UTF8);
test_set();
}