본문 바로가기
알고리즘

[python/nodejs] 백준 알고리즘 14681번

by MOOB 2020. 4. 24.

 

 

1. python

a = int(input())
b = int(input())

if(a > 0):
    if(b > 0):
        print(1)
    else:
        print(4)
else:
    if(b > 0):
        print(2)
    else:
        print(3)

 

인터넷 돌아다니다가 이 해법을 봤는데 진심 천재;;; 왜 이러시는진 모르겠지만 대단하네요...

print("3421"[(int(input())>0)+(int(input())>0)*2])

 

2. nodejs

여러줄 입력할 때랑 한 줄 입력할 때랑 입력 세팅이 다름... ㅋ...

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]);
	
  if (num1 > 0) {
      if (num2 > 0){
          console.log(1);   
      } else {
          console.log(4);
      }
  }
  else if (num1 < 0){
      if (num2 < 0){
          console.log(3)
      } else {
          console.log(2)
      }
  }
  process.exit();
});

 

느낀 점 : 나 사분면 헷갈려함

댓글