모든 일상

C# 백준 1427번 문제 소트인사이드 본문

코딩 공부/C#

C# 백준 1427번 문제 소트인사이드

통통푸린 2023. 1. 10. 16:32
728x90
반응형

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int[] arr = new int[str.Length];
            string result = "";
            for(int i = 0; i<str.Length; i++)
            {
                arr[i] = int.Parse(str.Substring(i, 1));       // 문자열 하나씩 잘라서 배열에 저장
            }
            Array.Sort(arr);                                           // 오름차순 정렬
            Array.Reverse(arr);                                    // 역순으로 - 내림차순 정렬

            for (int i = 0; i < str.Length; i++)
            {
                result += arr[i].ToString();
            }
            Console.WriteLine(result);
        }
    }
}

728x90
반응형