Notice
Recent Posts
Recent Comments
«   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
관리 메뉴

Share Garam's everyday life.

문자열 내림차순으로 배치하기 본문

알고리즘

문자열 내림차순으로 배치하기

가람스나이퍼님 (Joshua_Choi_Brother) 2021. 4. 22. 20:43

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

// 파라미터로 주어지는 문자열은 const로 주어집니다. 변경하려면 문자열을 복사해서 사용하세요.
char* solution(const char* s) {
    // return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요.
    int lengs=strlen(s);
    char* answer = (char*)malloc(strlen(s));
    strcpy(answer, s);
    for(int i=0;i<lengs;i++){
        for(int j=i+1;j<lengs;j++){
            if(answer[j]>answer[i])
            {
                int temp=answer[i];
                answer[i]=answer[j];
                answer[j]=temp;
            }
        }
    }
    return answer;
}

'알고리즘' 카테고리의 다른 글

수박수박?  (0) 2021.04.22
문자열 다루기 기본  (0) 2021.04.22
두 정수 사이의 합  (0) 2021.04.22
음양 더하기  (0) 2021.04.21
내적  (0) 2021.04.21