100000000>N의 숫자를 각 자리수를 뽑아서 내림차순으로 정렬하는 문제다.
Character로 받아서 바로 int로 바꿔주고 배열에 담는다.
그리고 그 배열에서 9~0까지 차례대로 출력~
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
/** | |
* https://www.acmicpc.net/problem/1427 | |
* BOJ 백준온라인져지 1427 소트인사이드 풀이 | |
*/ | |
int main(){ | |
char N = '0'; | |
int number[10] = {0}; // 0 ~ 9 | |
while(scanf("%c", &N) != EOF) number[N-48]++; | |
for(int i = 9; i >= 0; i--) while(number[i]--) printf("%d",i); | |
return 0; | |
} |
'IT > 알고리즘' 카테고리의 다른 글
BOJ 백준온라인져지 4948 베르트랑 공준 풀이 (0) | 2017.11.24 |
---|---|
BOJ 백준온라인져지 1181 단어 정렬 풀이 (0) | 2017.11.23 |
BOJ 백준온라인져지 9426 중앙값 측정 풀이 (0) | 2017.11.21 |
BOJ 백준온라인져지 1786 찾기 풀이 (1) | 2017.11.19 |
BOJ 백준온라인져지 5525 IOIOI 풀이(KMP) (0) | 2017.11.16 |