1427번: 소트인사이드


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
int input = 0;
vector<int> compare;
cin >> input;
int length = 0;
while(input >= 10)
{
compare.push_back(input%10);
input /= 10;
}
compare.push_back(input);
length = compare.size();
sort(compare.begin(), compare.end(), greater<int>());
for(int i = 0; i < length; i++)
{
cout << compare[i];
}
}
메모리 (KB) | 시간 (ms) | 코드 길이 (B) |
2024 | 0 | 488 |
N(= input)의 최대값이 1,000,000,000이기 때문에 int를 입력 받았다. 그리고 나머지 연산자를 통해 수를 분리해주고 벡터에 넣어주었다. 내림차순으로 정렬 후 출력해주면 끝이다.
Uploaded by N2T