웅재의 코딩세상

[프로그래머스] 문자열 내 마음대로 정렬하기 본문

코딩테스트/프로그래머스 - LV 1

[프로그래머스] 문자열 내 마음대로 정렬하기

웅드 2024. 2. 13. 23:10

 

  • 풀이
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int idx;
bool compare(string a, string b)
{
    if(a[idx]<b[idx])
        return true;
    else if(a[idx]==b[idx])
    {
        if(a<b)
            return true;
        return false;
    }
    return false;
}

vector<string> solution(vector<string> strings, int n) {

    idx = n;
    sort(strings.begin(), strings.end(), compare);
    return strings;
}
반응형