728x90
반응형

백준알고리즘

- Bronze 5 -

 #3046. R2 by JAVA and node.js 

 


 

문제

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

 

생일 선물로 숫자를 주는 사람이나 기쁜 마음으로 1년동안 외우면서 사는 사람이나 정상은 아닌,,,


 

접근 방법

S = (R1 + R2)/2

2S = R1 + R2

∴ R2 = 2S - R1

 


 

풀이

▶ JAVA

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int r1 = scan.nextInt();
        int s = scan.nextInt();

        scan.close();

        System.out.println(2 * s - r1);

    }
}

 

▶ node.js

var fs = require('fs');
var input = fs.readFileSync('/dev/stdin').toString().split(' ');
console.log(2 * input[1] - input[0]);

 


 

결과

 


 

 

 

 

 

End.

heisely's 괴발개발 개발일지

 

728x90
반응형

+ Recent posts