Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
31 |
Tags
- dfs
- KAKAO
- 백트래킹
- 이런게4문제
- 레벨2
- priority_queue
- 시뮬레이션
- C++
- find
- 백준
- Set
- STL
- 문자열
- 브루트포스
- 2018
- 레벨3
- 모의SW역량테스트
- 삼성SW테스트
- Map
- dp
- 코딩테스트
- swea
- BFS
- Sort
- 완전탐색
- substr
- 코딩스킬
- 프로그래머스
- 삼성
- 삼성SW역량테스트
Archives
- Today
- Total
-
[프로그래머스] 레벨 2 - 프린터 본문
https://programmers.co.kr/learn/courses/30/lessons/42587
코딩테스트 연습 - 프린터 | 프로그래머스
일반적인 프린터는 인쇄 요청이 들어온 순서대로 인쇄합니다. 그렇기 때문에 중요한 문서가 나중에 인쇄될 수 있습니다. 이런 문제를 보완하기 위해 중요도가 높은 문서를 먼저 인쇄하는 프린터를 개발했습니다. 이 새롭게 개발한 프린터는 아래와 같은 방식으로 인쇄 작업을 수행합니다. 1. 인쇄 대기목록의 가장 앞에 있는 문서(J)를 대기목록에서 꺼냅니다. 2. 나머지 인쇄 대기목록에서 J보다 중요도가 높은 문서가 한 개라도 존재하면 J를 대기목록의 가장 마지막에
programmers.co.kr
앞뒤로 빼거나 더할 수 있는 뎈을 써서 편리하게 풀었다.
또 마스킹을 해서 location 인덱스의 요소가 이동하더라도 편리하게 위치를 찾게 하였더니 편리하게 코딩할 수 있었다.
쉬운 문제.
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#include <string>
#include <vector>
#include <deque>
using namespace std;
int solution(vector<int> priorities, int location) {
int answer = 1;
deque<pair<int, int> > list;
for(int i=0; i<priorities.size(); i++){
int rank, mark;
rank = priorities[i];
if(i == location){
mark = 1;
list.push_back(make_pair(rank, mark));
continue;
}
mark = -1;
list.push_back(make_pair(rank, mark));
}
while(1){
int front = list.front().first;
bool isthis = (list.front().second == 1) ? true : false;
bool isthere_bigger = false;
if(!isthis){
// 더 큰 것 있나 찾아보고 있으면 빼서 맨뒤에 넣거나
// 없으면 앞에서 삭제하고 answer++;
for(int i=1; i<list.size(); i++){
if(list[i].first > front){
isthere_bigger = true;
break;
}
}
if(!isthere_bigger){
// 더 큰 것 없으면 인쇄.
list.pop_front();
answer++;
}
else{
// 더 큰 것 있으면 빼서 뒤에.
pair<int, int> f = list.front();
list.pop_front();
list.push_back(f);
}
}
else{
// 이것이라면 더 큰 것 있나 찾아보고 있으면 빼서 맨뒤에 넣거나
// 없으면 answer++;해서 break;
for(int i=1; i<list.size(); i++){
if(list[i].first > front){
isthere_bigger = true;
break;
}
}
if(!isthere_bigger){
break;
}
else{
pair<int, int> f = list.front();
list.pop_front();
list.push_back(f);
}
}
}
return answer;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
'1-4. 프로그래머스' 카테고리의 다른 글
[프로그래머스] 레벨 2 - 다리를 지나는 트럭 (0) | 2020.02.03 |
---|---|
[프로그래머스] 레벨 2 - 기능개발 (0) | 2020.02.03 |
[프로그래머스] 레벨 2 - 탑 (0) | 2020.02.03 |
[프로그래머스] 레벨 2 - 카카오프렌즈 컬러링북 (2017 카카오코드 예선) (0) | 2020.02.03 |
[프로그래머스] 레벨 2 - 124 나라의 숫자 (0) | 2020.02.02 |
Comments