8000 Create 11652.cpp · rinrin528/basic-algo-lecture@646634b · GitHub
[go: up one dir, main page]

Skip to content

Commit 646634b

Browse files
Create 11652.cpp
1 parent 628476e commit 646634b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

0x0F/11652.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)
0