Algorithm & Test/백준
[백준] 1427번: 소트인사이드 (C++)
Hyun__
2023. 8. 14. 11:36
string과 char를 잘 이용하면 되는 문제
string으로 입력을 받은 뒤
정렬 과정을 거쳐 하나씩 출력하면 된다
숫자를 입력 받아 자릿수마다 나누는 방식으로 접근할 수도 있지만
확실히 자릿수를 나눠서 하는 문제는 문자열로 해결하는 것이
더욱 수월하고 빠르게 해결할 수 있는 방법인 듯하다
// baekjoon 1427
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
// codes for fast I/O
void init(){
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
}
int main(){
init();
string input;
cin >> input;
unsigned long len = input.length();
char arr[len];
for(int i = 0; i < len; i++){
arr[i] = input[i];
}
sort(arr, arr+len,greater<>());
for(int i = 0; i < len; i++){
cout << arr[i];
}
}