일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Where
- 개발자의 책장
- 배열
- Developer_JoyKim
- 프로그래머스
- 역행자
- Hackerrank
- 개발자_조이킴
- for문
- 최강의 인생
- 코플릿
- 자바스크립트
- array.push()
- node.js
- 코딩공부
- Algorithms
- array.slice()
- SQL
- 블록체인
- JavaScript
- 알고리즘
- 재귀함수
- Programmers
- 정규표현식
- array
- join
- 코딩테스트
- 코드스테이츠
- select
- MySQL
Archives
- Today
- Total
CodingSpace
[HackerRank/Algorithms] Implementation - Number Line Jumps 본문
HackerRank/Algorithm
[HackerRank/Algorithms] Implementation - Number Line Jumps
개발자_조이킴 2022. 8. 29. 21:00Problem. Implementation - Number Line Jumps
Link.
https://www.hackerrank.com/challenges/kangaroo/problem?isFullScreen=true
Number Line Jumps | HackerRank
Can two kangaroo meet after making the same number of jumps?
www.hackerrank.com
Description.
You are choreographing a circus show with various animals. For one act, you are given two kangaroos on a number line ready to jump in the positive direction (i.e, toward positive infinity).
- The first kangaroo starts at location x1 and moves at a rate of v1 meters per jump.
- The second kangaroo starts at location x2 and moves at a rate of v2 meters per jump.
You have to figure out a way to get both kangaroos at the same location at the same time as part of the show. If it is possible, return YES, otherwise return NO.
Key Point.
My Answer.
'use strict';
const fs = require('fs');
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', function(inputStdin) {
inputString += inputStdin;
});
process.stdin.on('end', function() {
inputString = inputString.split('\n');
main();
});
function readLine() {
return inputString[currentLine++];
}
/*
* Complete the 'kangaroo' function below.
*
* The function is expected to return a STRING.
* The function accepts following parameters:
* 1. INTEGER x1
* 2. INTEGER v1
* 3. INTEGER x2
* 4. INTEGER v2
*/
function kangaroo(x1, v1, x2, v2) {
// Write your code here
let time = (x1 - x2) / (v2 - v1)
let isInt = Number.isInteger(time);
if(isInt === true && v1 > v2)
return "YES"
else
return "NO"
}
function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
const firstMultipleInput = readLine().replace(/\s+$/g, '').split(' ');
const x1 = parseInt(firstMultipleInput[0], 10);
const v1 = parseInt(firstMultipleInput[1], 10);
const x2 = parseInt(firstMultipleInput[2], 10);
const v2 = parseInt(firstMultipleInput[3], 10);
const result = kangaroo(x1, v1, x2, v2);
ws.write(result + '\n');
ws.end();
}
References.
'HackerRank > Algorithm' 카테고리의 다른 글
[HackerRank/Algorithms] Implementation - Repeated String (0) | 2022.09.01 |
---|---|
[HackerRank/Algorithms] Implementation - Cats and a Mouse (0) | 2022.08.30 |
[HackerRank/Algorithms] Warmup - Grading Students (0) | 2022.08.24 |
[HackerRank/Algorithms] Warmup - Time Conversion (0) | 2022.08.23 |
[HackerRank/Algorithms] Warmup - Birthday Cake Candles (0) | 2022.08.22 |
Comments