Skip to main content

How to get Input case data in Node.JS

Every website provides a different skeleton code to start with. 

BOJ

const input = require("fs").readFileSync("/dev/stdin").toString('\n');

console.log(input);



Programmers - just focus on the code itself, solution function for the logic

function solution(numbers) {
    var answer = [];
    return answer;
}



Groom 

const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

let data = [];
rl.on("line", function (line) {
  data.push(line);

  //console.log(data);
  data = line.split(" ").map((el) => el);

  console.log(data);
  // data = line.split(' ').map((el) => el);
  // data = line.split('').map((el) => +el);

  rl.close();
}).on("close", function () {
  process.exit();
});


//////////////////////////////////////////////////////////////////////////
const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

let input = [];

rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  let num1 = Number(input[0]);
  let num2 = Number(input[1]);

  let hundredSeatsNum2 = Math.floor(num2 / 100);
  let tenSeatsNum2 = Math.floor(num2 / 10) - hundredSeatsNum2 * 10;
  let oneSeatsNum2 = num2 % 10;

  console.log(num1 * oneSeatsNum2);
  console.log(num1 * tenSeatsNum2);
  console.log(num1 * hundredSeatsNum2);
  console.log(num1 * num2);

  process.exit();
});



Leetcode


Hackerrank 

Comments

Popular posts from this blog

The Complete React Guide by Max - Section 12: Adding Routing to our Burger Project

 220. Module Introduction - just intro 221. Building the checkout container  just create Checkout/checkoutSummary JS files  222. Setting up Routing & Routes < Switch > < Route path = "/checkout" component = { Checkout } /> < Route path = "/" exact component = { BurgerBuilder } /> </ Switch > order is matter and use <Switch> shows only route 223. Navigating to the checkout page  this . props . history . push ( "/checkout" ); yarn add react-router-app and cover {BrowserRouter} in index.js and then work on purchaseContinueHandler(that push('/checkout')) 224. Navigating back & to next page checkoutCancelled = () => { this . props . history . goBack (); }; checkoutContinued = () => { this . props . history . replace ( "/checkout/contact-data" ); }; pass props on each buttons with those 2 functions  225. Passing Ingredients...

The Complete React Guide by Max - Section 11: Multi-Page-Feeling in a Single-Page-App: Routing

 203. Extracting Route Parameters componentDidMount () {      axios . get ( "/posts/" + this . props . match . params . id ) . then ( ( response ) => { Changed from componentDidMount to componentDidMount as we are not updating this. this.props.match.params.id successfully passing route parameters and extracting them  205. Using switch to load a single route < Route path = "/" exact component = { Posts } /> < Switch > < Route path = "/new-post" component = { NewPost } /> < Route path = "/:id" exact component = { FullPost } /> </ Switch > <Switch> to ensure that only one route gets loaded at a time. 206. Navigating programmatically  postSelectedHandler = ( id ) => { //this.props.history.push({ pathname: "/" + id }); this . props . history . push ( "/" + id ); }; navigation is about a stack of pages. pu...

FE WebDev Routine Training Feb 09, 2021

 FE WebDev Routine Training Feb 09, 2021  A lot of things to do. DO FUCKING FOCUS!!!  Coding test - codewar 1 Kakao 2021 No.1 CSS - grid/ SCSS and Cloning(besthorrorscenes.com) JS - for of loop/  Sec9/ DOM array methods toy project React -   A bit of Yelp Portfolio -  List the 100JS projects Job hunting -  NAVER Finance(on 10th) Karrot for  internship  Apply SW maestro