본문 바로가기

Algorithm/Implementation

(C++) - 백준(BOJ) 9317 : Monitor DPI

반응형

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

 

9317번: Monitor DPI

Each input line will have 3 numbers, the decimal value D, the integer value \(\text{Resolution}_{\text{Horizontal}}\), and the integer value \(\text{Resolution}_{\text{Vertical}}\). An input line of three zeroes will signify end of input

www.acmicpc.net

간단한 구현 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

d, rh, rv를 선언 후 입력받습니다.

📔 풀이과정

공식에 맞춰 지역변수 w, h를 선언해 값을 구한 결과를 저장합니다.

📔 정답출력

형식에 맞게 출력해줍니다.


📕 Code

#include <bits/stdc++.h>
using namespace std;
double d, rh, rv;
int main(){
    while(1){
        cin >> d >> rh >> rv;
        if(!d && !rh && !rv) break;
        double w = 16 * d / sqrt(337);
        double h = 9 * w / 16;
        printf("Horizontal DPI: %.2f\n", rh / w);
        printf("Vertical DPI: %.2f\n", rv / h);
    }
}

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.