diff --git a/src/week2/BOJ2910/BOJ2910_V1.cpp b/src/week2/BOJ2910/BOJ2910_V1.cpp new file mode 100644 index 0000000..18943dd --- /dev/null +++ b/src/week2/BOJ2910/BOJ2910_V1.cpp @@ -0,0 +1,46 @@ +#include +using namespace std; +bool sorting_algorithm(tuple a, tuple b) { + if (get<1>(a) != get<1>(b)) { + return get<1>(a) > get<1>(b); + } + return get<2>(a) < get<2>(b); +} +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + int N,C; + cin >> N >> C; + + //입력 숫자, 입력 숫자 개수, 입력 숫자의 입력순서 + map > m; + vector > ret; + + for (int i = 0; i < N; i++) { + int temp; + cin >> temp; + if (m.find(temp) != m.end()) { + get<1>(m[temp])++; + } else { + m[temp] = {temp, 1, i}; + } + } + + for (auto it : m) { + ret.push_back(it.second); + } + + sort(ret.begin(), ret.end(), sorting_algorithm); + + for (auto it : ret) { + for (int i=0; i(it); i++) { + cout << get<0>(it) << " "; + } + } + + + return 0; +} \ No newline at end of file