본문 바로가기
[프로그래머스 C++]/LEVEL 1

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

by AKI(JUNI) 2025. 4. 10.

◈ 문제 설명

 


◈ 문제 설명 링크

코딩테스트 연습 - 문자열 내 마음대로 정렬하기 | 프로그래머스 스쿨

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 


◈ 작성 코드

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

vector<string> solution(vector<string> strings, int n) 
{
    sort(strings.begin(), strings.end(), [n](string a, string b)    // sort로 정렬
    {
        if(a[n] == b[n])
        {
            return a < b;
        }
        return a[n] < b[n];
    });
    
    
    return strings;
}