Programmers/Level 1
[프로그래머스 1] 문자열 내 마음대로 정렬하기 (C/C++)
워니-
2019. 10. 17. 03:55
#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 |