풀이과정
전역 변수 N을 선언해줘서 n 인덱스 값을 넣는다.
sort함수를 써서 cmp 조건에 따라 오름차순 정렬한다.
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int N;
bool cmp(string a, string b){
if(a[N] == b[N]) return a < b;
else return a[N] < b[N];
}
vector<string> solution(vector<string> strings, int n) {
vector<string> answer;
N = n;
sort(strings.begin(), strings.end(), cmp);
answer = strings;
return answer;
}
'🍞 Problem Solving > Programmers' 카테고리의 다른 글
[프로그래머스][Level1] 신규 아이디 추천 c++ (0) | 2022.09.03 |
---|---|
[프로그래머스][Level1] 신고 결과 받기 c++ (0) | 2022.09.03 |
[프로그래머스][Level1] 2016년 c++ (0) | 2022.09.03 |
[프로그래머스][Level1] 음양 더하기 c++ (0) | 2022.09.03 |
[프로그래머스][Level1] 완주하지 못한 선수 c++ (0) | 2022.09.03 |