프로그래머스(C++) - k번째 수

2025. 8. 18. 03:58·C++ 프로그래머스/Sort

●문제

 

●입출력

 

사용알고리즘 : sort

문제해석 : array배열의 2차원배열의 command[0]번부터 command[1]까지 자른뒤

정렬한뒤 command[3]배열값을 return하여 완성하면 return값 도출

 

풀이

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> solution(vector<int> array, vector<vector<int>> commands)
{
	vector<int> answer;

	for (int i = 0; i < commands.size(); i++)
	{
		vector<int> temp;
		for (int j = commands[i][0] - 1; j < commands[i][1]; j++)
		{
			temp.push_back(array[j]);
		}
		sort(temp.begin(), temp.end());
		answer.push_back(temp[commands[i][2] - 1]);
	}
	return answer;
}

 

점수 : 1

레벨 : 1

'C++ 프로그래머스 > Sort' 카테고리의 다른 글

프로그래머스(C++) - H-Index  (1) 2025.08.19
프로그래머스(C++) - 가장 큰 수  (0) 2025.08.18
Algorithm - Sorting  (0) 2025.08.13
프로그래머스(C++) - 명예의 전당(1)  (0) 2025.07.27
'C++ 프로그래머스/Sort' 카테고리의 다른 글
  • 프로그래머스(C++) - H-Index
  • 프로그래머스(C++) - 가장 큰 수
  • Algorithm - Sorting
  • 프로그래머스(C++) - 명예의 전당(1)
lucodev
lucodev
커피와 노트북 그리고 개발
  • lucodev
    루코 개발테이블
    lucodev
  • 전체
    오늘
    어제
    • 분류 전체보기 (210) N
      • Unreal 프로젝트 다이어리 (107) N
        • 첫번째 프로젝트 (73)
        • 두번째 프로젝트 (34) N
      • Unreal 팁 (8)
      • Unreal 디버깅 (8)
      • C++ 프로그래머스 (52)
        • Stack,Queue (7)
        • Hash (4)
        • Heap (2)
        • Sort (5)
        • Exhaustive search (5)
        • Greedy (2)
        • BFS , DFS (7)
        • Graph (2)
        • Dynamic Programming (1)
        • C++ Math (2)
        • 기타 문제 (14)
      • C++ 백준 (4)
      • C++ 팁 (1)
      • 개인 코테 & 스타디 <비공개> (29)
        • 코드 개인보관함 (9)
        • 코딩테스트+@ (11)
        • 알고리즘 스타디 (6)
        • 알고리즘 스타디 과제 (3)
        • 비공개 (0)
  • 인기 글

  • 최근 글

  • 최근 댓글

  • 링크

  • 공지사항

  • 블로그 메뉴

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

    언리얼 상호작용
    언리얼 motionmatching
    unreal inventory
    언리얼 모션매칭
    언리얼 parkour
    언리얼 behavior tree
    언리얼 프로그래스바
    언리얼
    unreal 모션매칭
    언리얼 인벤토리
    Unreal Parkour
    언리얼 파쿠르
    unreal 파쿠르
    언리얼 ui
    언리얼 컷씬
    언리얼 behaviortree
    언리얼 비헤이비어트리
    unreal 시퀀스
    unreal 인벤토리
    언리얼 시퀀스
  • hELLO· Designed By정상우.v4.10.3
lucodev
프로그래머스(C++) - k번째 수
상단으로

티스토리툴바