Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- CH01
- 선형분류
- 근구하기
- vector미분
- falsePosition
- 델타 rule
- graphical models
- 알고리즘
- 2018
- 스터디
- directed graphical model
- Fisher discriminant analysis
- Perceptron Convergence theorem
- chapter02
- chapter01
- 5397번
- bisection
- 인공지능
- 이것이 MySQL이다
- SCPC
- secant
- 선형판별분석
- 로지스틱 회귀
- undirected graphical model
- 1차예선
- 알고리즘대회
- 개발순서
- Numerical optimization
- 자바ORM표준JPA프로그래밍
- MySQL
Archives
- Today
- Total
computer_study
[탐색] BAEKJOON '1302'번 '베스트셀러'문제 (C++/python) 본문
문제 : www.acmicpc.net/problem/1302
-
문제 해결 아이디어
1. python에선 dictionary, c++에선 map함수를 이용하여, key값과 value값을 설정하고 문제를 해결한다.
2. 입력값들을 순회하며, 같은 값이 나올 때 마다 value값을 증가시켜, 마지막에 그중 최대값을 출력한다.
-
python
n = int(input())
books = {}
for _ in range(n):
book = input()
if book not in books:
books[book] = 1
else:
books[book] += 1
target = max(books.values())
array = []
for book, number in books.items():
if number == target:
array.append(book)
print(sorted(array)[0])
※ dictionary
-
c++
#include "iostream"
#include "string"
#include "map"
using namespace std;
int main(){
int n;
map<string, int> books;
scanf("%d",&n);
for(int i=0 ; i< n ; i++){
string tmp;
cin >> tmp;
if(books.count(tmp) == 0){
books.insert(make_pair(tmp,1));
}
else{
books.find(tmp)->second++;
}
}
int max = 0;
for(auto iter = books.begin(); iter != books.end(); iter++){
if(iter->second > max)
max = iter->second;
}
for(auto iter = books.begin(); iter != books.end(); iter++){
if(iter->second == max){
cout << iter->first << "\n";
return 0;
}
}
return 0;
}
※ map
'알고리즘 > 문제풀이' 카테고리의 다른 글
[c++] codeground 연습문제'우주정거장' (2018년도 SCPC 예선1차) (0) | 2020.08.17 |
---|---|
[c++] codeground 연습문제 '버스 타기'(2018년도 SCPC 예선1차) (0) | 2020.08.12 |
[탐색] BAEKJOON '1568'번 '새'문제 (C++/python) (0) | 2020.08.11 |
[탐색] BAEKJOON '1543'번 '문서 검색'문제 (C++/python) (0) | 2020.08.11 |
[재귀함수] BAEKJOON ' 7490 '번 '0 만들기 '문제 (C++/python) (0) | 2020.08.11 |
Comments