본문 바로가기

Algorithm/BAEKJOON

[BOJ] 1302번 베스트셀러 (C++)

728x90
반응형

https://www.acmicpc.net/problem/1302

 

1302번: 베스트셀러

첫째 줄에 오늘 하루 동안 팔린 책의 개수 N이 주어진다. 이 값은 1,000보다 작거나 같은 자연수이다. 둘째부터 N개의 줄에 책의 제목이 입력으로 들어온다. 책의 제목의 길이는 50보다 작거나 같고

www.acmicpc.net

 

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

int main() {
	int n, max = 0;
	string str, result;
	map<string, int> m;
	
	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> str;
		if(m.find(str) != m.end()){
			m[str]++;
		} else{
			m[str] = 1;
		}
	}

	for(auto it = m.begin(); it != m.end(); it++){
		if(max < it->second){
			max = it->second;
			result = it->first;
		}
	}
	
	cout << result << endl;
	return 0;
}
728x90
반응형

'Algorithm > BAEKJOON' 카테고리의 다른 글

[BOJ] 1263번 시간 관리 (C++)  (0) 2022.02.10
[BOJ] 14490번 백대열 (C++)  (0) 2022.02.06
[BOJ] 7656번 만능 오라클 (C++)  (0) 2022.02.05
[BOJ] 4358번 생태학 (C++)  (0) 2022.02.04
[BOJ] 19583번 싸이버개강총회 (C++)  (0) 2022.02.04