//https://www.acmicpc.net/problem/1032 #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| #include <algorithm> | |
| using namespace std; | |
| struct book{ | |
| int idx; | |
| int cnt; | |
| string title; | |
| book(); | |
| book(int idx, string title, int cnt) : idx(idx), title(title), cnt(cnt) {} | |
| }; | |
| bool cmp(book a, book b){ | |
| if(a.cnt != b.cnt) | |
| return a.cnt> b.cnt; | |
| else { | |
if(a.title.compare(b.title) < 0) return true; //사전 순으로 a가 b의 앞일 때 | |
| else return false; | |
| } | |
| } | |
| int main(){ | |
| vector<string> v; | |
| vector<book> l; | |
| int n; | |
| cin >> n; | |
| for(int i=0; i<n; ++i){ | |
| string s; | |
| cin >> s; | |
| v.push_back(s); | |
| } | |
| sort(v.begin(), v.end()); | |
| string m=v[0]; | |
| int idx=0; | |
| l.push_back(book(0, v[0], 1)); | |
| for(int i=1; i<n; ++i){ | |
| if(v[i].compare(v[i-1])==0) l[idx].cnt++; | |
| else{ | |
| l.push_back(book(i, v[i], 1)); | |
| idx++; | |
| } | |
| } | |
| sort(l.begin(), l.end(), cmp); | |
| cout << l[0].title; | |
| return 0; | |
| } |
'알고리즘 문제 풀이 > 1DP_과제(~180615)' 카테고리의 다른 글
| 180426_1236_성 지키기 (0) | 2018.04.26 |
|---|---|
| 180425_1568_새 (0) | 2018.04.25 |
| 180424_1068_트리 (0) | 2018.04.24 |
| 180423_1003_피보나치 함수 (0) | 2018.04.23 |
| 180423_3047_ABC (0) | 2018.04.23 |