치춘짱베리굿나이스

[백준] 6749 본문

Next in line

문제

You know a family with three children. Their ages form an arithmetic sequence: the difference in ages between the middle child and youngest child is the same as the difference in ages between the oldest child and the middle child. For example, their ages could be 5, 10 and 15, since both adjacent pairs have a difference of 5 years.

Given the ages of the youngest and middle children, what is the age of the oldest child?

입력

The input consists of two integers, each on a separate line. The first line is the age Y of the youngest child (0 ≤ Y ≤ 50). The second line is the age M of the middle child (Y ≤ M ≤ 50).

출력

The output will be the age of the oldest child.

풀이

const family = () => {
  let input = require("fs")
    .readFileSync("/dev/stdin")
    .toString()
    .trim()
    .split("\\n")
    .map(Number);
  console.log(input[1] + input[1] - input[0]);
};

family();

반성회

72바이트 코드는 대체 어떻게 한거지

'Javascript + Typescript > 자바스크립트로 알고리즘풀기' 카테고리의 다른 글

[백준] 2448  (0) 2022.03.18
[백준] 7287  (0) 2022.03.18
[백준] 1463  (0) 2022.03.17
[백준] 17478  (0) 2022.03.17
[백준] 1780  (0) 2022.03.17
Comments