sort의 compare 인자만 바꾸면 쉽다.
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int N;
bool comp(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) {
N = n;
sort(strings.begin(), strings.end(), comp);
return strings;
}'Coding_Test 연습 > Programmers' 카테고리의 다른 글
| [프로그래머스] (C++) LV1 문자열 내림차순으로 배치하기 (0) | 2022.04.26 |
|---|---|
| [프로그래머스] (C++) LV1 문자열 내 p와 y의 개수 (0) | 2022.04.26 |
| [프로그래머스] (C++) LV1 나누어 떨어지는 숫자 배열 (0) | 2022.04.25 |
| [프로그래머스] (C++) LV1 두 정수 사이의 합 (0) | 2022.04.25 |
| [프로그래머스] (C++) LV1 같은 숫자는 싫어 (0) | 2022.04.25 |