문제
1427번: 소트인사이드
첫째 줄에 정렬하고자하는 수 N이 주어진다. N은 1,000,000,000보다 작거나 같은 자연수이다.
www.acmicpc.net
💡 내 코드(C)
// [1427] 소트인사이드
#include <stdio.h>
#include <string.h> // strlen()
#define MAX 100000
void bubble_sort(char *n);
char n[MAX];
int main()
{
scanf("%s", n); // strlen() 사용하기 위해서 %s로 입력
bubble_sort(n);
printf("%s", n);
}
void bubble_sort(char *n) // 내림차순 정렬
{
int i, j;
int len = strlen(n);
char temp;
for (i = 0; i < len; i++) {
for (j = 0; j < len - (i + 1); j++) {
if (n[j] < n[j + 1]) {
temp = n[j];
n[j] = n[j + 1];
n[j + 1] = temp;
}
}
}
}
반응형
'Baekjoon > 정렬' 카테고리의 다른 글
[2751] 수 정렬하기2 (0) | 2019.06.26 |
---|---|
[2752] 세수정렬 (0) | 2019.05.19 |
[2750] 수 정렬하기 (0) | 2019.05.19 |
[11651] 좌표 정렬하기 2(C) (0) | 2019.05.19 |
[1026] 보물 (0) | 2019.05.12 |