백준 10818

Hyerin·2021년 12월 29일
0
post-thumbnail

문제

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

C# 풀이

using System;
using System.IO;

namespace baekjoon
{
    class Program
    {
        static void Main(string[] args)
        {
            // 표준 입출력 스트림 reader,writer 만들기
            // n, n개의 정수 입력받기
            // n을 int로 바꾸기, , n개의 정수를 분리하기, int로 바꾸기
            // 최솟값과 최댓값 공백으로 구분해 버퍼에 저장
            // 버퍼 한 번에 비우기

            StreamReader sr = new StreamReader(Console.OpenStandardInput());
            StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());

            string strNumCount = sr.ReadLine();
            string strNums = sr.ReadLine();

            int nNumCount = int.Parse(strNumCount); // 5
            string[] strArrNums = strNums.Split(' ');

            int nMin = int.Parse(strArrNums[0]); // 20
            int nMax = int.Parse(strArrNums[0]); // 20

            for (int i = 1; i < nNumCount; i++)
            {
                int nNum = int.Parse(strArrNums[i]); // 10, 35, 30, 7
                if (nMin > nNum) //20 > 10, 10 > 35, 10 > 30, 10 > 7
                {
                    nMin = nNum; // 10,7
                }
                if (nMax < nNum) 
                {
                    nMax = nNum; 
                }
            }

            sw.WriteLine(nMin);
            sw.WriteLine(nMax);

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

0개의 댓글