●문제

●입출력

문제풀이
문제를 설명하기에 앞서 이 지문은 난독증환자가 된거같은 진짜 개떡같은 지문이다
재해석된 글이 있다 이걸 보고오자
https://school.programmers.co.kr/questions/20326?question=20326
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
푼방법
벡터순회로 풀었다
전벡터와 후벡터값을 비교해서 값이 작은지 큰지 비교하여 값을 계산
#include <string>
#include <vector>
#include <stack>
using namespace std;
vector<int> solution(vector<int> prices)
{
//index, price
stack<pair<int, int>>prices_Stk;
vector<int> answer(prices.size(), 0);
for (int i = 0; i < prices.size(); i++)
prices_Stk.push({ i, prices[i] });
while (!prices_Stk.empty())
{
pair<int, int> current = prices_Stk.top();
prices_Stk.pop();
int idx = current.first;
int price = current.second;
for (int j = idx + 1; j < prices.size(); j++)
{
answer[idx]++;
if (price > prices[j])
break;
}
}
return answer;
}
--
stack유형의 문제인거같아 stack을 사용하긴했는데 그냥 2중for문 벡터순회만 사용하는게 더 좋았을지도..?
레벨 2
점수 1
'C++ 프로그래머스 다이어리 > Stack,Queue' 카테고리의 다른 글
| 프로그래머스(C++) - 괄호 회전하기 (0) | 2025.10.14 |
|---|---|
| 프로그래머스(C++) - 프로세스 (0) | 2025.10.08 |
| 프로그래머스(C++) - 기능개발 (0) | 2025.08.07 |
| Algorithm - Stack, Queue (0) | 2025.08.07 |
| 프로그래머스(C++) - 짝지어 제거하기 (0) | 2025.08.02 |
