프로그래머스(C++) - 주식가격

2025. 10. 8. 14:43·C++ 프로그래머스 다이어리/Stack,Queue

●문제

 

●입출력

 

문제풀이

문제를 설명하기에 앞서 이 지문은 난독증환자가 된거같은 진짜 개떡같은 지문이다

재해석된 글이 있다 이걸 보고오자

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
'C++ 프로그래머스 다이어리/Stack,Queue' 카테고리의 다른 글
  • 프로그래머스(C++) - 괄호 회전하기
  • 프로그래머스(C++) - 프로세스
  • 프로그래머스(C++) - 기능개발
  • Algorithm - Stack, Queue
lucodev
lucodev
커피와 노트북 그리고 개발
  • lucodev
    루코 개발테이블
    lucodev
  • 전체
    오늘
    어제
    • 분류 전체보기 (171)
      • Unreal5 프로젝트 다이어리 (73)
      • Unreal5 프로젝트 다이어리2 (11)
      • Unreal 팁 (8)
      • Unreal 디버깅 (8)
      • 코드 개인보관함 (8)
      • C++ 프로그래머스 다이어리 (49)
        • Stack,Queue (6)
        • Hash (4)
        • Heap (2)
        • Sort (5)
        • Exhaustive search (5)
        • Greedy (2)
        • BFS , DFS (6)
        • Graph (2)
        • Dynamic Programming (1)
        • C++ Math (2)
        • 기타 문제 (13)
      • 코딩테스트+@ (10) N
      • 알고리즘 스타디 (1)
      • 알고리즘 스타디 과제 (3)
  • 인기 글

  • 최근 글

  • 최근 댓글

  • 링크

  • 공지사항

  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 태그

    unreal 컷씬
    언리얼 로딩
    unreal loading
    언리얼 behaviortree
    언리얼 모션매칭
    unreal 모션매칭
    언리얼 behavior tree
    언리얼 foot step
    unreal 시퀀스
    unreal look at
    언리얼 로딩창
    언리얼 비헤이비어트리
    unreal sequence
    언리얼 컷씬
    언리얼 look at
    언리얼
    언리얼 motionmatching
    unreal 로딩
    언리얼 시퀀스
    언리얼 페이드 아웃
  • hELLO· Designed By정상우.v4.10.3
lucodev
프로그래머스(C++) - 주식가격
상단으로

티스토리툴바