forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path6.cpp
More file actions
21 lines (18 loc) ยท 697 Bytes
/
6.cpp
File metadata and controls
21 lines (18 loc) ยท 697 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <bits/stdc++.h>
#define MAX_VALUE 9
using namespace std;
int n = 15;
// ๋ชจ๋ ์์์ ๊ฐ์ด 0๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ๋ค๊ณ ๊ฐ์
int arr[15] = {7, 5, 9, 0, 3, 1, 6, 2, 9, 1, 4, 8, 0, 5, 2};
// ๋ชจ๋ ๋ฒ์๋ฅผ ํฌํจํ๋ ๋ฐฐ์ด ์ ์ธ(๋ชจ๋ ๊ฐ์ 0์ผ๋ก ์ด๊ธฐํ)
int cnt[MAX_VALUE + 1];
int main(void) {
for (int i = 0; i < n; i++) {
cnt[arr[i]] += 1; // ๊ฐ ๋ฐ์ดํฐ์ ํด๋นํ๋ ์ธ๋ฑ์ค์ ๊ฐ ์ฆ๊ฐ
}
for (int i = 0; i <= MAX_VALUE; i++) { // ๋ฐฐ์ด์ ๊ธฐ๋ก๋ ์ ๋ ฌ ์ ๋ณด ํ์ธ
for (int j = 0; j < cnt[i]; j++) {
cout << i << ' '; // ๋์ด์ฐ๊ธฐ๋ฅผ ๊ธฐ์ค์ผ๋ก ๋ฑ์ฅํ ํ์๋งํผ ์ธ๋ฑ์ค ์ถ๋ ฅ
}
}
}