Study hard
(c++)백준 11652번: 카드 본문
https://www.acmicpc.net/problem/11652
[풀이]
C++ STL의 sort함수를 사용한다.
적혀있는 수의 범위가 크므로 long long타입을 사용한다.
정렬 후 숫자 카드의 개수의 최댓값을 갱신하며 가장 많이 가지고 있는 정수를 찾는다.
#include <iostream>
#include <vector>
#include <algorithm>//sort
using namespace std;
int N;
vector<long long>v;
void input() {
long long n;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> n;
v.push_back(n);
}
}
void solution() {
input();
if (N == 1) {
cout << v[0] << '\n';
return;
}
sort(v.begin(), v.end());
int cnt = 1;
long long num = v[0];
int Max = -1;
for (int i = 1; i < N; i++) {
if (v[i - 1] == v[i]) {
cnt++;
if (Max < cnt) {
num = v[i - 1];
Max = cnt;
}
}
else {
cnt = 1;
}
}
cout << num << endl;
}
int main() {
solution();
return 0;
}
'백준 > 여러가지 문제들' 카테고리의 다른 글
(c++)백준 10828번: 스택 (0) | 2020.06.11 |
---|---|
(c++)백준 11004번: K번째 수 (0) | 2020.06.11 |
(c++)백준 10989번: 수 정렬하기 3 (0) | 2020.06.11 |
(c++)백준 10825번: 국영수 (0) | 2020.06.11 |
(c++)백준 10814번: 나이순 정렬 (0) | 2020.06.11 |