#include <string> #include <vector> #include <algorithm> using namespace std; int chk; bool cmp(string a, string b) { if(a[chk] <= b[chk]) { if(a[chk] == b[chk]) { if(a < b) { return true; } else { return false; } } return true; } else { return false; } } vector<string> solution(vector<string> strings, int n) { vector<string> answer; chk = n; sort(strings.begin(), strings.end(), cmp); answer = strings; return answer; } | cs |
'Programmers > Level 1' 카테고리의 다른 글
[프로그래머스 1] 문자열 내림차순으로 배치하기 (C/C++) (0) | 2019.10.17 |
---|---|
[프로그래머스 1] 문자열 내 p와 y의 개수 (C/C++) (0) | 2019.10.17 |
[프로그래머스 1] 두 정수 사이의 합 (C/C++) (0) | 2019.10.17 |
[프로그래머스 1] 나누어 떨어지는 숫자 배열 (C/C++) (0) | 2019.10.17 |
[프로그래머스 1] 같은 숫자는 싫어 (C/C++) (0) | 2019.10.17 |