반응형
https://school.programmers.co.kr/learn/courses/30/lessons/181851
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
답
#include <bits/stdc++.h>
using namespace std;
int solution(vector<int> rank, vector<bool> attendance) {
int answer = 0;
vector<vector<int>> temp;
for(int i=0;i<rank.size();i++){
if(attendance[i]==true){
temp.push_back({rank[i],i});
}
}
sort(temp.begin(),temp.end());
answer=10000*temp[0][1]+100*temp[1][1]+temp[2][1];
return answer;
}
int answer하고
이차원vector temp를 만들어준다.
rank의 크기만큼 for문을 돌리고(i)
attendance[i]가 참이면
temp에 rank[i]와 i를 넣어준다.
for문이 끝나고 temp를 정렬해준다.
(이차원vector을 sort를 사용하면 기본적으로는 a[0][0] 값으로 정렬한다. 아마도...)
anwer을 출력조건대로 출력해준다.
참고
sort가 이차원vector을 할때는 기본은
사전대로 정렬된다.
vector<vector<int>> vectorname ={{1,2},{2,1}};
sort(vectorname.begin(), vectorname.end());
이런 vector을 정렬하면
{1,2}, {2,1}
|
이렇게 정렬된다.
그니가 아마도
기봊ㄴ적으론
vectorname[][0] 으로 정렬을 하는것 같다.
끝
반응형
'c++ > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 배열 만들기 4(c++) (0) | 2023.12.24 |
---|---|
[프로그래머스] 할 일 목록(c++) (0) | 2023.12.24 |
[프로그래머스] 배열 만들기 6(c++) (0) | 2023.12.24 |
[프로그래머스] 문자열 잘라서 정렬하기(c++) (0) | 2023.12.24 |
[프로그래머스] 문자열 여러 번 뒤집기(c++) (2) | 2023.12.23 |