일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Algorithms
- array.slice()
- join
- 개발자_조이킴
- 재귀함수
- array
- MySQL
- 최강의 인생
- 프로그래머스
- select
- 코딩공부
- array.push()
- 배열
- 코딩테스트
- Where
- 코플릿
- SQL
- 정규표현식
- node.js
- 자바스크립트
- Developer_JoyKim
- 알고리즘
- 역행자
- Hackerrank
- Programmers
- JavaScript
- 블록체인
- 코드스테이츠
- for문
- 개발자의 책장
Archives
- Today
- Total
CodingSpace
[HackerRank/Algorithms] Warmup - Compare the Triplets 본문
HackerRank/Algorithm
[HackerRank/Algorithms] Warmup - Compare the Triplets
개발자_조이킴 2022. 9. 3. 23:37Problem. Warmup - Compare the Triplets
Link.
https://www.hackerrank.com/challenges/compare-the-triplets/problem?isFullScreen=true
Compare the Triplets | HackerRank
Compare the elements in two triplets.
www.hackerrank.com
Description.
Alice and Bob each created one problem for HackerRank. A reviewer rates the two challenges, awarding points on a scale from 1 to 100 for three categories: problem clarity, originality, and difficulty.
The rating for Alice's challenge is the triplet a = (a[0], a[1], a[2]), and the rating for Bob's challenge is the triplet b = (b[0], b[1], b[2]).
The task is to find their comparison points by comparing a[0] with b[0], a[1] with b[1], and a[2] with b[2].
- If a[i] > b[i], then Alice is awarded 1 point.
- If a[i] < b[i], then Bob is awarded 1 point.
- If a[i] = b[i], then neither person receives a point.
Comparison points is the total points a person earned.
Given a and b, determine their respective comparison points.
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 'compareTriplets' function below.
*
* The function is expected to return an INTEGER_ARRAY.
* The function accepts following parameters:
* 1. INTEGER_ARRAY a
* 2. INTEGER_ARRAY b
*/
function compareTriplets(a, b) {
let Alice = 0;
let Bob = 0;
for(let i = 0; i < 3; i++) {
if(a[i] > b[i])
Alice = Alice + 1;
else if(a[i] < b[i])
Bob = Bob + 1;
}
return [Alice, Bob];
}
function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
const a = readLine().replace(/\s+$/g, '').split(' ').map(aTemp => parseInt(aTemp, 10));
const b = readLine().replace(/\s+$/g, '').split(' ').map(bTemp => parseInt(bTemp, 10));
const result = compareTriplets(a, b);
ws.write(result.join(' ') + '\n');
ws.end();
}
References.
'HackerRank > Algorithm' 카테고리의 다른 글
[HackerRank/Algorithms] Strings - CamelCase (0) | 2022.09.06 |
---|---|
[HackerRank/Algorithms] Implementation - Cut the sticks (0) | 2022.09.04 |
[HackerRank/Algorithms] Warmup - Staircase (0) | 2022.09.03 |
[HackerRank/Algorithms] Implementation - Repeated String (0) | 2022.09.01 |
[HackerRank/Algorithms] Implementation - Cats and a Mouse (0) | 2022.08.30 |
Comments