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 | 29 | 30 |
Tags
- 문자열
- 프로그래머스
- 정렬
- 동적계획법
- String
- 코테
- 플로이드와샬
- 리시프
- MAP
- sql고득점kit
- 알고리즘
- set
- 스택
- dfs
- Dijkstra
- DP
- 코테준비
- 참고 문헌 : MACHINE LEARNING 기계학습 _ 오일석
- 다익스트라
- 코딩테스트연습
- 최대공약수
- 백준
- 다이나믹프로그래밍
- MySQL
- C++
- 시스템콜
- unordered_map
- 우선순위큐
- vector
- substr
Archives
- Today
- Total
YeJin's Footsteps
로또의 최고 순위와 최저 순위 본문
문제 링크
https://programmers.co.kr/learn/courses/30/lessons/77484
코딩테스트 연습 - 로또의 최고 순위와 최저 순위
로또 6/45(이하 '로또'로 표기)는 1부터 45까지의 숫자 중 6개를 찍어서 맞히는 대표적인 복권입니다. 아래는 로또의 순위를 정하는 방식입니다. 1 순위 당첨 내용 1 6개 번호가 모두 일치 2 5개 번호
programmers.co.kr
문제 풀이 코드
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <iostream>
using namespace std;
int rnk(int score){
if(score>=2) return (7-score);
else return 6;
}
vector<int> solution(vector<int> lottos, vector<int> win_nums) {
vector<int> answer;
unordered_map <int,int> m;
for(int i=0; i<win_nums.size(); i++){
m[win_nums[i]]++;
}
int cnt=0, cntZ=0;
for(int i=0; i<lottos.size(); i++){
if(lottos[i]==0){
cntZ++;
}
else{
if(m[lottos[i]]) cnt++;
}
}
int maxC=cnt+cntZ;
int minC=cnt;
answer.push_back(rnk(maxC));
answer.push_back(rnk(minC));
return answer;
}
unordered_map을 활용하여 문제를 풀었다!
한번에 맞춘 몇 안되는 문제 중 하나 ㅎㅎ

'Computer Science & Engineering > 알고리즘' 카테고리의 다른 글
2 x n 타일링 (0) | 2021.07.31 |
---|---|
문자열 압축 (0) | 2021.07.30 |
9370번: 미확인 도착지 (0) | 2021.07.21 |
1238번: 파티 (0) | 2021.07.20 |
2458번: 키 순서 (0) | 2021.07.19 |