Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
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
Tags
more
Archives
Today
Total
관리 메뉴

자이의 프로그래밍

Level 1. 문자열 내 마음대로 정렬하기 본문

Algorithm/Cases-Programmers

Level 1. 문자열 내 마음대로 정렬하기

Xi_kor 2020. 5. 5. 15:35

https://programmers.co.kr/learn/courses/30/lessons/12915

 

#include <string.h>
#include <vector>
#include <algorithm>

using namespace std;

vector<string> solution(vector<string> strings, int n) {
    
    for(int i=0; i<strings.size(); i++){
        for(int j=0; j<strings.size(); j++){
            if(strings[i][n]<strings[j][n]){
                string temp;
                temp=strings[j];
                strings[j]=strings[i];
                strings[i]=temp;
            }
            else if(strings[i][n]==strings[j][n]){
                if(strcmp(strings[i],strings[j])>0){
                    string temp;
                    temp=strings[i];
                    strings[i]=strings[j];
                    strings[j]=temp;
                }
            }
        }
    }
    
    return strings;
}

'Algorithm > Cases-Programmers' 카테고리의 다른 글

Level 1. 다트게임  (0) 2020.05.13
Level 1. 비밀지도  (0) 2020.05.11
Level 1. 수박수박수박수박수박수?  (0) 2020.05.05