728x90
반응형

백준알고리즘

- Bronze 4 -

 #14470. 전자레인지 by JAVA and node.js 

 


 

문제

출처: https://www.acmicpc.net/problem/14470 

 


 

접근 방법

if - else if - else 문으로 풀 수 있는 문제이다.

입력받은 A값이 0보다 작을 때에는 A℃~0℃ 가열시간 + 해동시간 + 0℃ ~ B℃ 가열시간을 구하면 되고,

입력받은 A값이 0보다 클 때에는 A℃ ~ B℃ 가열시간만 구하면 된다.

 


 

풀이

▶ JAVA

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt(); // 초기온도
        int b = scan.nextInt(); // 목표온도
        int c = scan.nextInt(); // 얼어있을 때 섭씨 1도당 가열시간
        int d = scan.nextInt(); // 해동시간
        int e = scan.nextInt(); // 얼어있지 않을 때 섭씨 1도당 가열시간
        scan.close();

        if(a < 0) { // 얼어있는 상태일 때
            System.out.println(-a * c + d + b * e);
        } else { // 얼어있지 않은 상태일 때
            System.out.println((b-a) * e);
        }
    }
}

 

▶ node.js

var fs = require('fs');
var input = fs.readFileSync('/dev/stdin').toString().trim().split('\n').map(Number);

var a = input[0]; // 초기온도
var b = input[1]; // 목표온도
var c = input[2]; // 얼어있을 때 섭씨 1도당 가열시간
var d = input[3]; // 해동시간
var e = input[4]; // 녹아있을 때 섭씨 1도당 가열시간

if(a < 0){
    console.log(-a * c + d + b * e);
} else {
    console.log((b - a) * e);
}

 


 

결과

 


 

 

 

 

 

End.

heisely's 괴발개발 개발일지

 

728x90
반응형

+ Recent posts