티스토리 뷰

1427번: 소트인사이드
https://www.acmicpc.net/problem/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)
20240488

N(= input)의 최대값이 1,000,000,000이기 때문에 int를 입력 받았다. 그리고 나머지 연산자를 통해 수를 분리해주고 벡터에 넣어주었다. 내림차순으로 정렬 후 출력해주면 끝이다.


Uploaded by N2T

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
링크
Total
Today
Yesterday