Skip to main content

Posts

[BAEKJOON Online Judge + Node.js] 2292: Honeycomb

  I did't use while loop that much so didn't come up what to do. While loop create a loop that execute a specific statement. So, the main point of this problem is "prevNum + max * 6" input = 13, output = 3 https://www.acmicpc.net/problem/2292 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while const input = require ( "fs" ). readFileSync ( "/dev/stdin" ). toString () ; let count = 1 ; let max = 1 ; // set the range while (max < input) { max += count * 6 ; count ++ ; } console . log (count) ; // prevNum + count * 6 // 1 so +6 every loop! // 2 - 7, 5 // 8 - 19, 11 // 20 - 37, 17 // 38 - 61, 23
Recent posts

29/06/2021 TIL

1. PS(BOJ/Programmers) update programmers questions on github  2. Project (DividendDB & OXINION) with JS/React Fundamental of JS course  3. CS for Interview summary interview questions 

Basic input and output of JavaScript(Node.js)

Groom(readline module) const input = require ( 'fs' ) . readFileSync ( '/dev/stdin' ) . toString ( ) . split ( '\n' ) ; BOJ(FS module) // Run by Node.js const readline = require ( "readline" ) ; const rl = readline . createInterface ( { input : process . stdin , output : process . stdout , } ) ; let input = [ ] ; rl . on ( "line" , function ( line ) { // let num = line.split(' ').map(Number); for one line input . push ( line . trim ( ) ) ; // rl.close(); } ) . on ( "close" , function ( ) { const length = parseInt ( input [ 0 ] ) ; const values = input [ 1 ] . split ( " " ) . map ( Number ) ; console . log ( `your length is ${ length } & your arr is ${ values } ` ) ; process . exit ( ) ; } ) ;

[BAEKJOON Online Judge + Node.js] 1181: Word sort

This is my first attempt  const input = require ( "fs" ). readFileSync ( "/dev/stdin" ). toString (). split ( " \n " ) ; const count = Number (input[ 0 ]) ; // 13 // 1. shortest word.length // 2. If the length is the same, in alphabetical order // sort() ? let newArr = [] ; // insert all elements in array let shortest = input[ 1 ]. length ; // just initial value for ( let i = 1 ; i <= count ; i ++ ) { newArr . push (input[i]) ; } // remove duplicated elements in array let removedArr = newArr . filter ( ( item , index ) => newArr . indexOf (item) === index) ; removedArr . sort ( ( a , b ) => { return a . length - b . length ; } ) ; console . log (removedArr) ; i cannot get the correct answer as my answer keeps mixing the order like  [  'i',  'no',  'it',  'im',  'but',  'wont',  'more',  'wait',  'yours', 'cannot',  'hesitate' ...

Basic input and output of JavaScript(Node.js)

Goorm (readline module) // Run by Node.js const readline = require ( "readline" ) ; const rl = readline . createInterface ( { input : process .stdin, output : process .stdout, } ) ; let input = [] ; rl . on ( "line" , function ( line ) {     // let num = line.split(' ').map(Number); for one line input . push ( line . trim ()) ; // rl.close(); } ). on ( "close" , function () { const length = parseInt (input[ 0 ]) ; const values = input[ 1 ]. split ( " " ). map ( Number ) ; console . log ( `your length is ${ length } & your arr is ${ values } ` ) ; process . exit () ; } ) ; BackJoon (fs module) let fs = require ( "fs" ) ; let input = fs . readFileSync ( "/dev/stdin" ). toString (). split ( " \n " ) ;