Coding_Test 연습/Programmers

[프로그래머스] (C++) LV1 문자열 내 마음대로 정렬하기

Codetesing 2022. 4. 26. 09:40

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;
}