웅재의 코딩세상
[프로그래머스] 문자열 내 마음대로 정렬하기 본문
- 풀이
#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;
}
반응형
'코딩테스트 > 프로그래머스 - LV 1' 카테고리의 다른 글
[프로그래머스] 최소직사각형 (0) | 2024.02.14 |
---|---|
[프로그래머스] 삼총사 (0) | 2024.02.14 |
[프로그래머스] k번째수 (0) | 2024.02.13 |
[프로그래머스] 가운데 글자 가져오기 (0) | 2024.02.09 |
[프로그래머스] 같은 숫자는 싫어 (0) | 2024.02.09 |