1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int N; bool compare(string a, string b){ if(a[N] != b[N]) return a[N] < b[N]; else{ return a < b; } } vector<string> solution(vector<string> strings, int n) { N = n; sort(strings.begin(), strings.end(), compare); return strings; } int main(void){ ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); vector<string> strings{"abce", "abcd", "cdx"}; int n = 2; vector<string> answer = solution(strings, n); for(int i = 0; i < answer.size(); i++){ cout<<answer[i]<<" "; } return 0; } | cs |
'Problem-solving > 프로그래머스' 카테고리의 다른 글
프로그래머스 - 문자열 내림차순으로 배치하기 (C++) (0) | 2020.03.05 |
---|---|
프로그래머스 - 문자열 내 p와 y의 개수 (C++) (0) | 2020.03.05 |
프로그래머스 - 두 정수 사이의 합 (C++) (0) | 2020.03.04 |
프로그래머스 - 나누어 떨어지는 숫자 배열 (C++) (0) | 2020.03.04 |
프로그래머스 - 같은 숫자는 싫어 (C++) (0) | 2020.03.04 |
댓글