알고리즘
[알고리즘] c++ cpp 문자열 내 마음대로 정렬하기
keel_im
2020. 10. 21. 10:22
반응형
포인트
1. c++ 에서는 자료구조에서 정렬을 할 수 있는 기준 함수를 정의할 수 있습니다.
이 기준 함수를 가지고 정렬을 합니다.
🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다.
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int i;
bool cmp(string &a, string &b) {
if (a[i] < b[i]) return true;
else if (a[i] == b[i]) {
if (a <= b) return true;
}
return false;
}
vector<string> solution(vector<string> strings, int n) {
i = n;
sort(strings.begin(), strings.end(), cmp);
return strings;
}
반응형