일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- select
- MySQL
- Hackerrank
- 알고리즘
- 개발자의 책장
- array.slice()
- 최강의 인생
- Programmers
- 개발자_조이킴
- array
- JavaScript
- 코플릿
- array.push()
- 배열
- 코딩공부
- Where
- 재귀함수
- join
- Algorithms
- 프로그래머스
- Developer_JoyKim
- node.js
- 역행자
- 정규표현식
- 블록체인
- 코딩테스트
- SQL
- 자바스크립트
- 코드스테이츠
- for문
Archives
- Today
- Total
CodingSpace
[HackerRank/Algorithms] Warmup - Time Conversion 본문
Problem. Warmup - Time Conversion
Link.
https://www.hackerrank.com/challenges/mini-max-sum/problem?isFullScreen=true
Description.
Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers.
Then print the respective minimum and maximum values as a single line of two space-separated long integers.
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 'timeConversion' function below.
*
* The function is expected to return a STRING.
* The function accepts STRING s as parameter.
*/
function timeConversion(s) {
// Write your code here
let format = s.slice(8);
let hour = s.slice(0, 2);
let minAndSecond = s.slice(2, 8);
if(format === 'PM' && Number(hour) < 12)
hour = (Number(hour) + 12).toString()
else if(format === 'AM' && Number(hour) === 12)
hour = "00"
return hour + minAndSecond;
}
function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
const s = readLine();
const result = timeConversion(s);
ws.write(result + '\n');
ws.end();
}
References.
'HackerRank > Algorithm' 카테고리의 다른 글
[HackerRank/Algorithms] Implementation - Number Line Jumps (0) | 2022.08.29 |
---|---|
[HackerRank/Algorithms] Warmup - Grading Students (0) | 2022.08.24 |
[HackerRank/Algorithms] Warmup - Birthday Cake Candles (0) | 2022.08.22 |
[HackerRank/Algorithms] Warmup - Mini-Max Sum (0) | 2022.08.22 |
[HackerRank/Algorithms] Warmup - Plus Minus (0) | 2022.08.21 |
Comments