본문 바로가기

알고리즘/프로그래머

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

#include <string>
#include <vector>
#include <algorithm>
#include <string.h>
using namespace std;

string solution(string s) {
    string answer = "";
    
    string get_string=s;
    int length=s.length();
    char arr[length];
    int temp=0;
    
    strcpy(arr,s.c_str());
    
    
    for(int i=0; i<length-1; i++){
            for(int k=0; k<length; k++){
                
                if(arr[k]<arr[k+1]){
                    temp=arr[k];
                    arr[k]=arr[k+1];
                    arr[k+1]=temp;
                }   
            }
    }
    
    get_string=arr;
    return get_string;
    
    
    
    
    return answer;
}

'알고리즘 > 프로그래머' 카테고리의 다른 글

문자열 내 p와 y의 개수  (0) 2019.11.08
나누어 떨어지는 숫자 배열  (0) 2019.11.08
문자열을 정수로 바꾸기  (0) 2019.11.08
시저 암호  (0) 2019.11.08
수박수박수  (0) 2019.11.08