10867번: 중복 빼고 정렬하기 (acmicpc.net)

 

 

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

namespace _230124_1
{
    class Program
    {
        static void Main(string[] args)
        {
            StreamReader sr = new StreamReader(Console.OpenStandardInput());
            StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
            int N = int.Parse(sr.ReadLine());
            int[] arr = Array.ConvertAll(sr.ReadLine().Split(' '), int.Parse); //띄어쓰기로 구분한 정수형 배열만들기

            HashSet<int> set = new HashSet<int>(); //중복값을 허용하지 않고 hash값으로 데이터 관리
            Array.Sort(arr);
            for (int i = 0; i < arr.Length; i++)
                set.Add(arr[i]);  

            foreach (var num in set)
                sw.Write("{0} ", num);

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

StreamReader를 통해 띄어쓰기로 구분되는 정수배열을 만들 때 더욱 간소화된 스크립트를 사용할 수 있게 되었습니다.

'Algorithm > BOJ' 카테고리의 다른 글

C#) [BOJ] 9375 패션왕 신해빈 ★  (1) 2023.01.24
C#) [BOJ] 2461 대표 선수 ★★  (0) 2023.01.24
C#) [BOJ] 1018 체스판 다시 칠하기  (0) 2023.01.23
C#) [BOJ] 2231 분해합  (0) 2023.01.23
C#) [BOJ] 2501 약수 구하기  (0) 2023.01.23

+ Recent posts