본문 바로가기

[Programmers] 짝수와 홀수 // 짝수와 홀수 function solution(num) { return num % 2 === 0 ? "Even" : "Odd" }
[Programmers] 문자열 내림차순으로 배치하기 function solution(s) { return s.split("").sort().reverse().join(""); }
[BAEKJOON] 평균 (1546번) // const input = require("fs").readFileSync("/dev/stdin").toString().trim().split(" "); const input1 = "3\n40 80 60".toString().trim().split("\n"); // 75.0 const input2 = "3\n10 20 30".toString().trim().split("\n"); // 66.666667 const input3 = "4\n1 100 100 100".toString().trim().split("\n"); // 75.25 const input4 = "5\n1 2 4 8 16".toString().trim().split("\n"); // 38.75 const input5 = "2\n3 10"..
[BAEKJOON] 상수 (2908번) // const input = require("fs").readFileSync("/dev/stdin").toString().trim().split(" "); const input = "734 893".toString().trim().split(" "); function getConst(input) { let input1 = input[0].split("").reverse().join(""); let input2 = input[1].split("").reverse().join(""); console.log(input1 > input2 ? input1 : input2); } getConst(input);
[BAEKJOON] 나머지 (3052번) // const input = require("fs").readFileSync("/dev/stdin").toString().trim().split("\n"); // const input = "1\n2\n3\n4\n5\n6\n7\n8\n9\n10".toString().trim().split("\n"); // const input = "42\n84\n252\n420\n840\n126\n42\n84\n420\n126".toString().trim().split("\n"); const input = "39\n40\n41\n42\n43\n44\n82\n83\n84\n85".toString().trim().split("\n"); function getRestNum(input) { let numArr = input...
[BAEKJOON] A+B -2 (2558번) // const input = require("fs").readFileSync("/dev/stdin").toString().split("\n"); const input = "1\n2".toString().split("\n"); function aPlusB(input) { let a = Number(input[0]); let b = Number(input[1]); console.log(a + b); } aPlusB(input);
[BAEKJOON] 더하기 사이클 (1110번) // const input = require("fs").readFileSync("/dev/stdin").toString().trim().split(" "); const input = "26".toString(); function addFunction(input) { let num = Number(input); let sum = 0; let answer = 0; while (true) { sum = Math.floor(num / 10) + num % 10; num = (num % 10 ) * 10 + sum % 10; answer++; if(Number(input) === num) break; } console.log(answer); } addFunction(input);
[BAEKJOON] 단어의 개수 (1152번) // const input = require("fs").readFileSync("/dev/stdin").toString().trim().split(" "); const input = "".toString().trim().split(" "); function countTheWordsInString(input) { let answer = input[0] === "" ? 0 : input.length; console.log(answer); } countTheWordsInString(input);