layout: post
title: "[백준] 1427번_소트인사이드"
date: 2019-05-09
desc: "백준 1427번"
keywords: "Algorithm"
categories: [Algorithm]
tags: [백준, 알고리즘, 1427번, 소트인사이드, C++]
icon: icon-html
백준_1427번
소트인사이드
문제
배열을 정렬하는 것은 쉽다. 수가 주어지면, 그 수의 각 자리수를 내림차순으로 정렬해보자.
입력
첫째 줄에 정렬하고자하는 수 N이 주어진다. N은 1,000,000,000보다 작거나 같은 자연수이다.
출력
첫째 줄에 자리수를 내림차순으로 정렬한 수를 출력한다.
예제 입력 1
2143
예제 출력 1
4321
출처
- 문제를 번역한 사람: baekjoon
- 빠진 조건을 찾은 사람: bvba [djm03178](https://www.acmicpc.net/user/djm03178
알고리즘 분류
소스코드
#include <iostream>
#include <string>
using namespace std;
void descSort();
string str;
int main()
{
int num;
cin >> num;
str = to_string(num);
descSort();
cout << str;
return 0;
}
void descSort()
{
int temp;
for(int i=0; i<str.length(); i++) {
for(int j=0; j<str.length()-(i+1); j++) {
if(str[j] < str[j+1]) {
temp = str[j+1];
str[j+1]=str[j];
str[j]=temp;
}
}
}
}
댓글 영역