일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 프로그래머스
- algorithm #알고리즘 #백준
- 2020.03.16
- game jam
- rendering pipeline
- C
- 백준
- graphics
- 2020.02.23
- 논문
- 참조자
- TIP
- 독서
- Conjugate Gradient
- 알고리즘
- Til
- UNORDERED_MAP
- Implicit method
- oprerator
- ppt
- ComputeShader
- C++
- sparse matrix
- Algorithm
- Overloading
- class
- 알고리즘연습
- stretch force
- 학습용
- numerical method
Archives
- Today
- Total
OSgood의 개발일기
[프로그래머스] LEVEL2 탑문제(C++) 본문
프로그래머스라는 사이트의 문제의 해설을 올려보고자 한다. 문제는 아래 URL에 접속해서 읽어보면 될 듯 싶다.
https://programmers.co.kr/learn/courses/30/lessons/42588
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 | #include <string> #include <vector> using namespace std; vector<int> solution(vector<int> heights) { vector<int> answer; answer.resize(heights.size(),0); int nowheight; for (int i =heights.size()-1;i>=0;i--) { int j= i-1; nowheight = heights[i]; while(heights[j] <= nowheight) { j--; } j = j+1; if(j<0) { j =0; } answer[i] =j; } return answer; } | cs |
이 문제를 푼 방식은 간단하다. vector에 저장된 요소들을 하나씩 꺼내서 살펴보면서 그것보다 앞쪽에 있는 요소들과 값을 비교하여 꺼낸 요소보다 큰 값이 발견되면 while을 안들어게되고 그 부분에 값을 업데이트하게 된다. 쉽게 말하면 for문을 두번 돌려서 값을 비교하되 특정조건이 만족되면 break를 걸어준다는 소리이다.
출처 - 프로그래머스(https://programmers.co.kr/)
'Algorithm > Algorithm 문제 연습' 카테고리의 다른 글
[백준] 1715번 카드 정렬하기 (0) | 2020.03.08 |
---|---|
[백준] 2583번 영역 구하기 (0) | 2020.02.23 |
[백준] 14867번 물통문제 (0) | 2020.02.15 |
[CodeUp]2016 천단위 구분기호 (0) | 2019.09.10 |
[프로그래머스] LEVEL2 기능개발(C++) (0) | 2019.01.13 |
Comments