8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 628476e commit 646634bCopy full SHA for 646634b
0x0F/11652.cpp
@@ -0,0 +1,30 @@
1
+// http://boj.kr/f3feaf22016f4c9687b84ab6be2f4389
2
+#include <bits/stdc++.h>
3
+using namespace std;
4
+
5
+int n;
6
+long long a[100005];
7
8
+int main(void) {
9
+ ios::sync_with_stdio(0);
10
+ cin.tie(0);
11
+ cin >> n;
12
+ for(int i = 0; i < n; i++)
13
+ cin >> a[i];
14
+ sort(a, a+n);
15
+ int cnt = 0;
16
+ long long mxval = -(1ll << 62) - 1; // 1을 long long으로 형변환하지 않고 1 << 62로 작성시 int overflow 발생
17
+ int mxcnt = 0;
18
+ for(int i = 0; i < n; i++){
19
+ if(i == 0 || a[i-1] == a[i]) cnt++; // i가 0인 경우 앞쪽 식이 true이기 때문에 a[i-1]을 참조하지 않음
20
+ else{
21
+ if(cnt > mxcnt){
22
+ mxcnt = cnt;
23
+ mxval = a[i-1];
24
+ }
25
+ cnt = 1;
26
27
28
+ if(cnt > mxcnt) mxval = a[n-1]; // 제일 마지막 수가 몇 번 등장했는지를 별도로 확인
29
+ cout << mxval;
30
+}
0 commit comments