전체 글
-
[프로그래머스/해시/Lv.3] 베스트앨범프로그래머스/해시 2020. 6. 25. 21:31
문제 설명 코드 #include #include #include #include #include using namespace std; bool f(pair a, pair b){ return a.first>b.first; } vector solution(vector genres, vector plays) { vector answer; unordered_map map1; for(int i=0;isecond,i->first)); } for(map::iterator i=map2.begin();i!=map2.end();i++){ vector temp; for(int j=0;jsecond){ temp.push_back(make_pair(plays[j],j)); } } sort(temp.begin(),temp.end..
-
[프로그래머스/해시/Lv.2] 위장프로그래머스/해시 2020. 6. 25. 21:30
문제 설명 코드 #include #include #include using namespace std; int solution(vector clothes) { int answer = 1; int cnt=1; unordered_map u; for(auto i : clothes){ u[i[1]]++; } if(u.size()==1) { answer = clothes.size(); return answer; } for(auto i : u){ answer*=i.second+1; } return answer-1; } 소감 unordered_map에 저장하니 종류별 개수를 세기 편했다. 경우의 수 세기를 복잡하게 할 뻔했는데 진부분 집합이 생각나서 쉽게 풀 수 있었다.
-
[프로그래머스/탐욕법/Lv.1] 체육복프로그래머스/탐욕법(Greedy) 2020. 6. 25. 21:03
문제 설명 코드 #include #include #include using namespace std; int solution(int n, vector lost, vector reserve) { int answer = 0; bool check[31]={false,}; answer = n-lost.size(); if(lost.size()==0 || reserve.size()==0) return answer; sort(lost.begin(),lost.end()); sort(reserve.begin(),reserve.end()); for(int i=0;i