본문 바로가기
알고리즘/백준 BOJ

[ BOJ/C# ] 2751 수 정렬하기 2

by 왹져박사 2023. 8. 23.

https://www.acmicpc.net/problem/2751

 

2751번: 수 정렬하기 2

첫째 줄에 수의 개수 N(1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄부터 N개의 줄에는 수가 주어진다. 이 수는 절댓값이 1,000,000보다 작거나 같은 정수이다. 수는 중복되지 않는다.

www.acmicpc.net

List.Sort()를 이용하여 오름차순으로 간단하게 정리하였다. 

using System;

namespace _2751
{
    class Program
    {
        static void Main()
        {
            StreamReader sr = new StreamReader(Console.OpenStandardInput());
            StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());

            int n = int.Parse(sr.ReadLine());
            List<int> list = new List<int>();

            for(int i = 0; i < n; i++)
            {
                list.Add(int.Parse(sr.ReadLine()));
            }
            list.Sort();

            for(int i = 0; i < list.Count; i++)
            {
                sw.WriteLine(list[i]);
            }

            sr.Close();
            sw.Flush();
            sw.Close();
        }
    }
}

'알고리즘 > 백준 BOJ' 카테고리의 다른 글

[ BOJ/C# ] 2839 설탕 배달  (0) 2023.08.26
[ BOJ/C# ] 2844 알람 시계  (0) 2023.08.25
[ BOJ/C# ] 10828 스택  (0) 2023.08.23
[ BOJ/C# ] 10845 큐  (0) 2023.08.22
[ BOJ/C# ] 2675 문자열 반복  (0) 2023.08.21