C# 백준 1085번 직사각형에서 탈출

2022. 1. 3. 17:10C#/[백준] 기본 수학2

문제

코드 :

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

namespace _7
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] inputdata = input.Split(' ');
            //2 1 4 4
            int x = Convert.ToInt32(inputdata[0]);
            int y = Convert.ToInt32(inputdata[1]);
            int w = Convert.ToInt32(inputdata[2]);
            int h = Convert.ToInt32(inputdata[3]);

            int min = 0;

            int xd;
            int yd;
            //2
            //1
            xd = Math.Abs(x - 0);
            yd = Math.Abs(y - 0);

            if ((w - x) < xd) //w-x > 2
                xd = w - x; //2
            if ((h - y) < yd) //h - y > 3
                yd = h - y; //1

            if (xd > yd)
                min = yd;
            else
                min = xd;

            Console.WriteLine(min);
        }
    }
}