본문 바로가기
👩‍💻 Programming/Coding Test 문제 풀이

[BaekJoon] 18108번 1998년생인 내가 태국에서는 2541년생?!_JavaScript

by codingBear 2022. 4. 1.
728x90
반응형

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

 

18108번: 1998년생인 내가 태국에서는 2541년생?!

ICPC Bangkok Regional에 참가하기 위해 수완나품 국제공항에 막 도착한 팀 레드시프트 일행은 눈을 믿을 수 없었다. 공항의 대형 스크린에 올해가 2562년이라고 적혀 있던 것이었다. 불교 국가인 태국

www.acmicpc.net


Question

ICPC Bangkok Regional에 참가하기 위해 수완나품 국제공항에 막 도착한 팀 레드시프트 일행은 눈을 믿을 수 없었다. 공항의 대형 스크린에 올해가 2562년이라고 적혀 있던 것이었다.

불교 국가인 태국은 불멸기원(佛滅紀元), 즉 석가모니가 열반한 해를 기준으로 연도를 세는 불기를 사용한다. 반면, 우리나라는 서기 연도를 사용하고 있다. 불기 연도가 주어질 때 이를 서기 연도로 바꿔 주는 프로그램을 작성하시오.

Input

서기 연도를 알아보고 싶은 불기 연도 y가 주어진다. (1000 ≤ y ≤ 3000)

Output

불기 연도를 서기 연도로 변환한 결과를 출력한다.


Example Input

2541

Example Output

1998

My Solutions

const fs = require("fs");
const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt";
let input = fs.readFileSync(filePath).toString().trim();

solution(+input);

function solution(y) {
  console.log(y - 543);
}

예제 출력을 보면 예제 입력보다 543이 작은 값이 출력됨을 볼 수 있다. 따라서 입력값에 543을 뺀 값을 출력하면 된다.

참고로 input 앞의 '+' 연산자는 string을 number로 바꿔주는 기능을 한다.


함께 보기

1. '+' 연산자

https://en.wikibooks.org/wiki/JavaScript/Operators#Arithmetic_operators

 

JavaScript/Operators - Wikibooks, open books for an open world

JavaScript has the arithmetic operators +, -, *, /, and %. These operators function as the addition, subtraction, multiplication, division, and modulus operators, and operate very similarly to other languages. Multiplication and division operators will be

en.wikibooks.org

728x90
반응형

댓글