문제의 의도는 주어진 수를 문자열로 받아 정렬시키는 것으로 보인다...
하지만 수가 고작 10자리이기 때문에, 벡터로도 추우우웅분히 해결 가능하다.
1. 문자열로 입력받기
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
const int MAX = 10e+8;
int main() {
ios::ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
string str;
cin >> str;
sort(str.begin(), str.end(), greater<char>());
cout << str;
return 0;
}
2. int형으로 입력받기
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
const int MAX = 10e+8;
ll gcd(ll a, ll b) { for (; b; a %= b, swap(a, b)); return a; }
vector<int> vec;
int main() {
ios::ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int num;
cin >> num;
// 한자리씩 나누기
while (num) {
vec.push_back(num % 10);
num /= 10;
}
sort(vec.begin(), vec.end(), greater<int>());
for (int& i : vec) cout << i;
return 0;
}
'BOJ_단계별로 풀어보기(9단계~) > [11단계] 정렬' 카테고리의 다른 글
[백준 11651] 좌표 정렬하기 2 (0) | 2022.03.09 |
---|---|
[백준 11650] 좌표 정렬하기 (0) | 2022.03.09 |
[백준 2108] 통계학 (0) | 2022.03.08 |
[백준 10989] 수 정렬하기 3 (0) | 2022.03.08 |
[백준 2751] 수 정렬하기 2 (0) | 2022.03.08 |