문제의 의도는 주어진 수를 문자열로 받아 정렬시키는 것으로 보인다...

하지만 수가 고작 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;
}

+ Recent posts