상세 컨텐츠

본문 제목

백준#10818 - 최소, 최대

C#/알고리즘

by McRobbin 2020. 4. 8. 13:10

본문

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

 

10818번: 최소, 최대

첫째 줄에 정수의 개수 N (1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄에는 N개의 정수를 공백으로 구분해서 주어진다. 모든 정수는 -1,000,000보다 크거나 같고, 1,000,000보다 작거나 같은 정수이다.

www.acmicpc.net

배열 카테고리의 최소, 최대 문제 입니다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _10818
{
    class Program
    {
        static void Main(string[] args)
        {
            int size = int.Parse(Console.ReadLine());
            string[] splitInput = Console.ReadLine().Split(' ');
            List<int> intList = new List<int>();
            foreach (string s in splitInput)
                intList.Add(int.Parse(s));
            intList.Sort();
            Console.WriteLine("{0} {1}", intList[0], intList[intList.Count - 1]);
        }
    }
}
 
 
 

갯수와 문자열을 받아 split하여 string 배열을 만들었습니다. foreach문 사용, 하나씩 Parse하여 intList에

추가했습니다.

 

intList.Sort()함수를 사용해 이를 오름차순 정렬하고 0번째와 마지막 인덱스를 각각 출력했습니다.

'C# > 알고리즘' 카테고리의 다른 글

백준#2577 - 숫자의 개수  (0) 2020.04.08
백준#2562 - 최댓값  (0) 2020.04.08
백준#1110 - 더하기 사이클  (0) 2020.04.08
백준#5585 - 거스름돈  (0) 2020.04.08
백준#10951 - A+B - 4  (0) 2020.04.08

관련글 더보기