[백준] C# : TV 크기 (1297번)

ssu_hyun·2022년 9월 15일
0

Data Structure & Algorithm

목록 보기
62/67
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Baekjoon
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            double d = input[0];  // D = TV 대각선 길이
            double h = input[1];  // H = TV의 높이 비율
            double w = input[2]; // W = TV의 너비 비율

            double ratio;  // 원래 크기로 만들기 위해 곱해야하는 배율

            // (h*n)^2 + (w*n)^2 = d^2  => 피타고라스 공식 이용
            ratio = Math.Sqrt( d*d / (h*h + w*w));

            // 구한 배율 곱하기
            h *= ratio;
            w *= ratio;

            // 내림해서 출력
            Console.WriteLine($"{Math.Truncate(h)} {Math.Truncate(w)}");
        }
    }
}
  • 올림 : Math.Ceiling(double값)
  • 내림 : Math.Truncate(double값)
  • 반올림 : Math.Round(double값, 자릿수)

0개의 댓글