#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
string n;
cin >> n;
sort(n.rbegin(), n.rend());
int num = stoi(n); //string에 있는 stoi함수를 사용하여 int로 형변환한다.
//s(tring)to(int) stoi로 생각
cout << num;
}
int로 받아와서 자릿수별로 수를 계산할 필요없이 한번에 string으로 받아온뒤 정렬하고 int로 형변환한다.
다른 방법
수를 int로 받아오고 그것에서 내림차순으로 있는 개수만큼 출력한다.
'Algorithm > Baekjoon' 카테고리의 다른 글
[C++] 백준 1543 문서 검색 (0) | 2021.02.04 |
---|---|
[C++] 백준 10814 나이순 정렬 (0) | 2021.02.03 |
[C++] 백준 1920 수 찾기 (0) | 2021.02.02 |
[C++] 백준 5397 키로거 (0) | 2021.02.02 |
[C++] 백준 1966 프린터 큐 (0) | 2021.02.01 |