그럴듯한 개발 블로그
[프로그래머스 고득점kit] 스택/큐_같은 숫자는 싫어(c++)

https://school.programmers.co.kr/learn/courses/30/parts/12081 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include #include using namespace std; vector solution(vector arr) { vector answer; queue q; for (int i = 0; i < arr.size(); i++) { if (q.size() == 0) { q.push(arr[i]); continue ; } if (q.back() != arr[i]) q.push(arr..

[프로그래머스 고득점kit] 해시_베스트앨범(c++)

https://school.programmers.co.kr/learn/courses/30/parts/12077 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include #include #include using namespace std; bool greater_plays(pair a, pair b) { return (a.second > b.second); // 내림차순으로 정렬 } bool unique_greater_plays(pair a, pair b) { if (a.second == b.second) return a.first <..

[프로그래머스 고득점kit] 해시_위장(c++)

https://school.programmers.co.kr/learn/courses/30/parts/12077 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include #include using namespace std; int solution(vector clothes) { int answer = 1; unordered_map map; vector type; for (int i = 0; i < clothes.size(); i++) { if (map.find(clothes[i][1]) == map.end()) { map[clothes..

article thumbnail
STL 해시
<language>/c++ 2023. 4. 6. 20:21

unordered_set vector 처럼 자료형도 선언할때 지정해줘야 함 s.insert(val) val을 추가함 unordered_set은 중복을 허용하지 않는다(같은 값을 집어넣으면 씹힌다) s.erase(val) val을 찾아서 제거함 (성공 시 1을 실패 시 0을 반환) s.find(val) val을 찾아서 iterator을 반환한다.(못찾으면 s.end()를 반환) s.size() 크기 반환 s.count(val) val이 몇개 있는지 반환 (unordered_set은 중복 안되서 무조건 1, 0) 해시는 반복문으로 출력해보면 뒤죽박죽으로 나오는데 해시의 특성이다 (정렬되어 보관되지 않는다) unordered_multiset 중복이 허용된다. erase 주의 같은 값을 가지고있는 모든 요소를 ..

백준 1620 (c++) 나는야 포켓몬 마스터 이다솜
<algorithm>/백준 2023. 4. 6. 20:15

https://www.acmicpc.net/problem/1620 1620번: 나는야 포켓몬 마스터 이다솜 첫째 줄에는 도감에 수록되어 있는 포켓몬의 개수 N이랑 내가 맞춰야 하는 문제의 개수 M이 주어져. N과 M은 1보다 크거나 같고, 100,000보다 작거나 같은 자연수인데, 자연수가 뭔지는 알지? 모르면 www.acmicpc.net // 회사에 있는 사람 #include #include #include #include #include using namespacestd; intmain() { ios::sync_with_stdio(0),cin.tie(0); unordered_mapmap; intsize, n; stringinput; vectordogam; cin >> size >> n; dogam.p..

백준 7785 (c++) 회사에 있는 사람
<algorithm>/백준 2023. 4. 6. 17:11

https://www.acmicpc.net/problem/7785 7785번: 회사에 있는 사람 첫째 줄에 로그에 기록된 출입 기록의 수 n이 주어진다. (2 ≤ n ≤ 106) 다음 n개의 줄에는 출입 기록이 순서대로 주어지며, 각 사람의 이름이 주어지고 "enter"나 "leave"가 주어진다. "enter"인 경우는 www.acmicpc.net // 회사에 있는 사람 #include #include #include #include #include using namespacestd; intmain() { ios::sync_with_stdio(0),cin.tie(0); unordered_setset; stringname, status; intn; cin >> n; while (n--) { cin >> ..