Priceless
[백준] 1427번: 소트인사이드 (C++) 본문

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];
}
}
'Algorithm & Test > 백준' 카테고리의 다른 글
[백준] 1439번: 뒤집기 (C++) (0) | 2023.08.16 |
---|---|
[백준] 4796번: 캠핑 (C++) (0) | 2023.08.16 |
[백준] 2503번: 숫자 야구 (C++) (0) | 2023.08.13 |
[백준] 1654번: 랜선 자르기 (C++) (0) | 2023.08.10 |
[백준] 2108번: 통계학 (C++) 2트 (0) | 2023.08.10 |