Little Jay

[C++] 백준 1302번 - 베스트셀러 본문

알고리즘/BOJ

[C++] 백준 1302번 - 베스트셀러

Jay, Lee 2022. 1. 11. 15:19

map을 활용한 기본적인 문제

#include <iostream>
#include <map>
using namespace std;

int n;
map<string, int> m;

int main() {

	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	cin >> n;
	while (n--) {
		string s;
		cin >> s;
		++(m[s]);
	}
	pair<string, int> p;
	int max = 0;
	for (auto s : m) {
		if (s.second > max) {
			max = s.second;
			p = s;
		}
			
	}

	cout << p.first << '\n';

	return 0;

}

 

Comments