๋ฌธ์ œ

์ฒœ๋‚˜๋ผ ๋ฏผํ˜ธ์„ฑ์˜ ์ง€์˜ ๊ณต์ฃผ๋‹˜์€ ๋งค์šฐ ์•„๋ฆ„๋‹ต๋‹ค. ๊ณต์ฃผ๋‹˜ ์ž์‹ ๋„ ์ด ์„ธ์ƒ ๊ทธ ๋ˆ„๊ตฌ๋ณด๋‹ค ์ž์‹ ์ด ์•„๋ฆ„๋‹ต๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๊ณ  ์žˆ๋‹ค. ๊ณต์ฃผ๋‹˜์€ ์ž์‹ ์˜ ์•„๋ฆ„๋‹ค์›€์ด ์„ธ์›”์˜ ์ €ํŽธ์œผ๋กœ ์‚ฌ๋ผ์ง€๋Š” ๊ฒƒ์„ ๋งค์šฐ ๋‘๋ ค์›Œํ•œ๋‹ค. ๊ทธ๋ž˜์„œ ํ•˜๋ฃจ์—๋„ ์ˆ˜์‹ญ ์ˆ˜๋ฐฑ ๋ฒˆ์”ฉ ๊ฑฐ์šธ์„ ๋ณด๋ฉฐ ์ž์‹ ์˜ ๋ชจ์Šต์ด ์—ฌ์ „ํžˆ ์•„๋ฆ„๋‹ค์šด์ง€ ํ™•์ธ์„ ๊ฑฐ๋“ญํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋˜ ์–ด๋Š ๋‚ , ์„ธ์ƒ์˜ ๋‹ค์–‘ํ•œ ์žฅ๋ฉด๋“ค์„ ๋‹ด๊ณ  ์‹ถ์—ˆ๋˜ ๊ณต์ฃผ๋‹˜์˜ ๋งˆ๋ฒ•๊ฑฐ์šธ์€ ๋งค์ผ ๋˜‘๊ฐ™์€ ๋ชจ์Šต๋งŒ์„ ๋น„์ถ”๋Š” ์ž์‹ ์˜ ์šด๋ช…์— ์ขŒ์ ˆํ•˜๋ฉฐ ์•ž์œผ๋กœ์˜ ์šด๋ช…์„ ๊ฐœ์ฒ™ํ•˜๊ธฐ๋กœ ๊ฒฐ์‹ฌํ–ˆ๋‹ค. ๋งˆ๋ฒ•๊ฑฐ์šธ์€ ๋งค์ผ ์ž์‹ ์˜ ์‹ฌ๋ฆฌ์ƒํƒœ์— ๋”ฐ๋ผ ๊ฑฐ์šธ์— ๋น„์นœ ๊ณต์ฃผ๋‹˜์˜ ๋ชจ์Šต์„ ์ขŒ/์šฐ ๋˜๋Š” ์ƒ/ํ•˜๋กœ ๋ฐ˜์ „์‹œ์ผœ ๋น„์ถ”๊ธฐ๋กœ ํ•œ๋‹ค. ๋งˆ๋ฒ•๊ฑฐ์šธ์˜ ์‹ฌ๋ฆฌ์ƒํƒœ๋Š” 1๋ถ€ํ„ฐ 3๊นŒ์ง€์˜ ์ž์—ฐ์ˆ˜๋กœ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ˆซ์ž๊ฐ€ ํด์ˆ˜๋ก ๋” ํ™”๊ฐ€ ๋‚œ ์ƒํƒœ๋ฅผ ์˜๋ฏธํ•œ๋‹ค. ๋งˆ๋ฒ•๊ฑฐ์šธ์˜ ์‹ฌ๋ฆฌ์ƒํƒœ๊ฐ€ 1์ผ ๋•Œ๋Š” ์ง€์˜ ๊ณต์ฃผ๋‹˜์˜ ๋ชจ์Šต์„ ์žˆ๋Š” ๊ทธ๋Œ€๋กœ ํ‘œํ˜„ํ•˜๊ณ , 2์ผ ๋•Œ๋Š” ์ขŒ/์šฐ๋กœ ๋ฐ˜์ „๋œ ๋ชจ์Šต์„, 3์ผ ๋•Œ๋Š” ์ƒ/ํ•˜๋กœ ๋ฐ˜์ „๋œ ๋ชจ์Šต์„ ํ‘œํ˜„ํ•œ๋‹ค. ์ •์‚ฌ๊ฐํ˜• ํ˜•ํƒœ์˜ ๋งˆ๋ฒ•๊ฑฐ์šธ์˜ ํฌ๊ธฐ์™€ ๊ฑฐ์šธ์— ๋น„์นœ ์ง€์˜ ๊ณต์ฃผ๋‹˜์˜ ์›๋ž˜ ๋ชจ์Šต, ๋งˆ๋ฒ•๊ฑฐ์šธ์˜ ์‹ฌ๋ฆฌ์ƒํƒœ๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ๋งˆ๋ฒ•๊ฑฐ์šธ์— ๋น„์นœ ์ง€์˜ ๊ณต์ฃผ๋‹˜์˜ ๋ชจ์Šต์„ ์ถœ๋ ฅํ•˜๋ผ.

 

์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

 

ํ•ด๊ฒฐ

const fs = require('fs');

const { start } = require('repl');
const stdin = (process.platform === 'linux'
    ? fs.readFileSync('/dev/stdin').toString()
    : `8
OOOOOOOO
OKKOOEEO
OKKOOEEO
OOOSSOOO
OOOSSOOO
OAOOOOAO
OOAAAAOO
OOOOOOOO
3`
).match(/[^\r\n]+/g);

const s = stdin
const state = Number(s[s.length-1])
let answer = [];

// 1์ผ๋•Œ ๊ทธ๋Œ€๋กœ
if (state == 1){
  for (let i=1; i<s.length-1; i++){
    console.log(s[i])
  }

// 2์ผ๋•Œ ์ขŒ์šฐ๋ฐ˜์ „
} else if (state == 2){
  for (let i=1; i<s.length-1; i++){
    const letter = s[i].split('')
    for (let j=letter.length-1; j>=0; j--){
      if (j == letter.length-1){
        answer.push([letter[j]])
      } else {
        answer[answer.length-1].push(letter[j])
      }
    }
  }

// 3์ผ๋•Œ ์ƒํ•˜๋ฐ˜์ „
} else {
  for (let i=s.length-2; i>0; i--){
    console.log(s[i])
  }
}

console.log(answer.join('\n').replace(/,/g,''))

1. ํด๋ž˜์Šค ์ƒ์„ฑ์ž ๋งค์จ๋“œ - ๋งค๊ฐœ๋ณ€์ˆ˜

// ๋งค๊ฐœ๋ณ€์ˆ˜ ๋ฏธ๋ฆฌ ์„ ์–ธํ•˜๊ธฐ
class Car {
    color: string; // ์•„๋ž˜์˜ ์ƒ์„ฑ์ž๋งค์„œ๋“œ์— ์‚ฌ์šฉ๋œ๋‹ค๋ฉด, ๋ฏธ๋ฆฌ ์„ ์–ธ์„ ํ•ด์ค˜์•ผ ํ•œ๋‹ค.

    constructor(color: string) {
        this.color = color;
    }
}

// ๋˜๋Š”, ์ƒ์„ฑ์ž ๋งค์„œ๋“œ์˜ ๋งค๊ฐœ๋ณ€์ˆ˜์— 'public' ๋˜๋Š” 'readonly' 
class Car {
    constructor(public color: string) {  
        this.color = color;
    }
}

const bmw = new Car("red")

 

 

2. ์ ‘๊ทผ ์ œํ•œ์ž (Access modifier) : public

// Carํด๋ž˜์Šค
class Car {
    name: string = "car"  // public name: string = "car" ์™€ ๋™์ผ
    color: string;
    constructor(color: string) {
        this.color = color;
    }
    start() {
        console.log("start")
    }
}

// ์ž์‹ํด๋ž˜์Šค
class Bmw extends Car {   
    constructor(color: string) {
        super(color);
    }
    showName() {
        console.log(super.name)  // ์ž์‹ํด๋ž˜์Šค์—์„œ ์‚ฌ์šฉ๊ฐ€๋Šฅ
    }
}

const z4 = new Bmw("black")  // ํด๋ž˜์Šค ์ธ์Šคํ„ด์Šค ์ ‘๊ทผ ๊ฐ€๋Šฅ

 

 

3. ์ ‘๊ทผ ์ œํ•œ์ž (Access modifier) : private

// Carํด๋ž˜์Šค
class Car {
    private name: string = "car"  // #name: string = "car" ์™€ ๋™์ผ
    color: string;
    constructor(color: string) {
        this.color = color;
    }
    start() {
        console.log("start")
        console.log(this.name)   // Car ํด๋ž˜์Šค์—์„œ๋งŒ ๋‚ด๋ถ€์—์„œ๋งŒ ์‚ฌ์šฉ๊ฐ€๋Šฅ(์ž์‹ํด๋ž˜์Šค์—์„œ ์‚ฌ์šฉ๋ถˆ๊ฐ€)
                                 // console.log(this.#name)๋กœ๋„ ํ‘œํ˜„ ๊ฐ€๋Šฅ
    }
}

 

 

4. ์ ‘๊ทผ ์ œํ•œ์ž (Access modifier) : protected

class Car {
    protected name: string = "car" 
    color: string;
    constructor(color: string) {
        this.color = color;
    }
    start() {
        console.log("start")
    }
}

// ์ž์‹ํด๋ž˜์Šค
class Bmw extends Car {   
    constructor(color: string) {
        super(color);
    }
    showName() {
        console.log(super.name)  // ์ž์‹ํด๋ž˜์Šค์—์„œ ์‚ฌ์šฉ๊ฐ€๋Šฅ
    }
}

const z4 = new Bmw("black")
console.log(z4.name) // ์—๋Ÿฌ๋ฐœ์ƒ: ํด๋ž˜์Šค ์ธ์Šคํ„ด์Šค๋กœ ์ ‘๊ทผ ๋ถˆ๊ฐ€

 

 

5. static ์ •์  ๋ฉค๋ฒ„ ๋ณ€์ˆ˜

// static ์ •์  ๋ฉค๋ฒ„ ๋ณ€์ˆ˜
class Car {
    name: string = "car";
    static wheels = 4;

    start() {
        console.log("start")
        console.log(this.name)
        console.log(Car.wheels)  // static์„ ์‚ฌ์šฉํ• ๋•Œ๋Š”, this๊ฐ€ ์•„๋‹Œ Class๋ช…์„ ์ ์–ด์•ผํ•œ๋‹ค.
    }
}

console.log(Car.wheels)

 

 

6. ์ถ”์ƒ ํด๋ž˜์Šค

abstract class Car {
    color: string;
    constructor(color: string) {
        this.color = color
    }
                  
    abstract doSometing():void // ์ƒ์†๋ฐ›๋Š” ๊ณณ์—์„œ '๊ตฌ์ฒด์ ์ธ ๊ธฐ๋Šฅ'์„ ๊ตฌํ˜„ํ•ด์ฃผ์–ด์•ผ ํ•จ
}

// const car = new Car("red")  // ์˜ค๋ฅ˜ ๋ฐœ์ƒ: ์ถ”์ƒ ํด๋ž˜์Šค๋Š” new๋ฅผ ์ด์šฉํ•ด์„œ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์—†์Œ

class Bmw extends Car {        // ์˜ค์ง ์ƒ์†์„ ํ†ตํ•ด์„œ๋งŒ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Œ
    constructor(color: string) { 
        super(color);
    }

    doSomething(){             // ์ƒ์†๋ฐ›๋Š” ๊ณณ์—์„œ '๊ตฌ์ฒด์ ์ธ ๊ธฐ๋Šฅ'์„ ๊ตฌํ˜„ํ•ด์คŒ
        alert(3)
    }
}

const z4 = new Bmw("black")

 

๋ฌธ์ œ

๊ฐ€๋ญ„์— ์ฐŒ๋“  ์‹ ์ดŒ์„ ์œ„ํ•ด์„œ ๊ตญ๋ ฌ์ด๋Š” ์„ธ ์นธ์œผ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋Š” ์‹ ์ดŒ์— ๋น„๋ฅผ ๋‚ด๋ฆด ๊ฒƒ์ด๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๊ตญ๋ ฌ์ด๋Š” ๋ฌด๋Šฅํ•ด์„œ ๊ฐ ์นธ๋งˆ๋‹ค ๋น„๋ฅผ ๋‚ด๋ฆฌ์ง€ ๋ชปํ•˜๊ณ , ๋‘ ์นธ์— ๋™์ผํ•˜๊ฒŒ ๋น„๋ฅผ ๋‚ด๋ฆฌ๋Š” ๊ฒƒ๋งŒ ํ•  ์ˆ˜ ์žˆ๋‹ค.

1๋ฒˆ์งธ ์นธ, 2๋ฒˆ์งธ ์นธ์— ๋™์‹œ์— ๋ฟŒ๋ฆฌ๋Š” ๋น„์˜ ๊ฐ•์ˆ˜๋Ÿ‰์„ a cm, 1๋ฒˆ์งธ ์นธ, 3๋ฒˆ์งธ ์นธ์— ๋™์‹œ์— ๋ฟŒ๋ฆฌ๋Š” ๋น„์˜ ๊ฐ•์ˆ˜๋Ÿ‰์„ b cm, 2๋ฒˆ์งธ ์นธ, 3๋ฒˆ์งธ ์นธ์— ๋™์‹œ์— ๋ฟŒ๋ฆฌ๋Š” ๋น„์˜ ๊ฐ•์ˆ˜๋Ÿ‰์„ c cm๋ผ๊ณ  ํ•˜์ž. a, b, c๋Š” ๋ชจ๋‘ ์–‘์˜ ์‹ค์ˆ˜์—ฌ์•ผ ํ•œ๋‹ค. ๊ฐ€๋ญ„์— ์ฐŒ๋“  ์‹ ์ดŒ์ด๋ผ๋„ ๋น„๊ฐ€ ๋„ˆ๋ฌด ๋งŽ์ด ์˜ค๋ฉด ์ƒ๋‹นํžˆ ๊ณค๋ž€ํ•˜๊ณ , ๋น„๊ฐ€ ๋„ˆ๋ฌด ์กฐ๊ธˆ ์™€๋„ ๊ณค๋ž€ํ•˜๋‹ค. ๊ทธ๋ž˜์„œ ๊ฐ ์นธ์— ํ•ด๋‹นํ•˜๋Š” ์ง€์—ญ์€ ๊ฐ•์ˆ˜๋Ÿ‰์ด ์ •ํ™•ํžˆ di cm๊ฐ€ ๋˜์–ด์•ผ ํ•œ๋‹ค. ์ด๋•Œ ์ •ํ™•ํ•œ a, b, c์˜ ๊ฐ’์„ ๊ตฌํ•˜์—ฌ๋ผ.

 

์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

 

ํ•ด๊ฒฐ

const fs = require('fs');

const { start } = require('repl');
const stdin = (process.platform === 'linux'
    ? fs.readFileSync('/dev/stdin').toString()
    : `5 8 6`
).match(/[^\r\n]+/g);

const input = (() => {
let line = 0;
  return () => stdin[line++];
})();

const [d1,d2,d3] = input().split(' ').map(Number)

// d1 = a+b, d2 = a+c, d3 = b+c
// d1 + d2 = a+b+a+c 
// d1 + d2 = 2a + d3
// d1 + d2 - d3 = 2a
// d1 + d2 - d3 / 2 = a

const a = (d1 + d2 - d3) / 2
const b = (d1 + d3 - d2) / 2 
const c = (d2 + d3 - d1) / 2


let isSuccess = 1;
if (a <= 0 || b <= 0 || c <= 0){
  isSuccess = -1
}

console.log(isSuccess)
isSuccess > 0 ? console.log(a.toFixed(1),b.toFixed(1),c.toFixed(1)): null;

+ Recent posts