https://www.acmicpc.net/problem/1388
1388번: 바닥 장식
형택이는 건축가이다. 지금 막 형택이는 형택이의 남자 친구 기훈이의 집을 막 완성시켰다. 형택이는 기훈이 방의 바닥 장식을 디자인했고, 이제 몇 개의 나무 판자가 필요한지 궁금해졌다. 나��
www.acmicpc.net
javascript를 주 언어로 삼아야 하는데 도대체가 문법을 정확히 숙지를 못해서 쉬운 문제부터 차근차근 풀기 시작했다.
이번에 사용한 개념은 함수를 통한 객체의 정의와 비동기를 활용한 입출력, 문자열 파싱이다. 한가지 주의할 점은 자바스크립트에서 파싱을 할 때 간혹 ''이 들어가는 경우가 있다. 이것만 제외하여 파싱한 배열이 길이를 더해서 문제를 해결하면 쉽게 해결할 수 있다.
//1. 객체를 정의해서 풀어보자!
//2. 비동기를 이용해서 풀어보자!
const readline = require('readline')
const input = []
const rl = readline.createInterface({
output: process.stdout,
input: process.stdin
})
function floor_decoration() {
this.value = []
this.N = 0
this.M = 0
this.parsing = function(input) {
const temp = input.shift().split(' ').map((x) => parseInt(x))
this.N = temp[0]
this.M = temp[1]
this.value = input
}
this.solution = function() {
let w = 0, h = 0
for(let i = 0; i < this.N; i++) {
let str = ''
for(let j = 0; j < this.M; j++) {
str += this.value[i][j]
}
let len = 0
const res = str.split('|')
res.forEach(element => {
if(element !== '') len++
});
w += len
}
for(let i = 0; i < this.M; i++) {
let str = ''
for(let j = 0; j < this.N; j++) {
str += this.value[j][i]
}
let len = 0
const res = str.split('-')
res.forEach(element => {
if(element !== '') len++
});
h += len
}
console.log(w + h)
}
}
rl.on('line', (line) => {
input.push(line)
}).on('close', () => {
const fd = new floor_decoration()
fd.parsing(input)
fd.solution()
})
'백준' 카테고리의 다른 글
백준17249 - 태보태보 총난타 (0) | 2020.08.06 |
---|---|
백준11383 - 뚊 (0) | 2020.08.05 |
백준2479 - 경로 찾기 (0) | 2020.07.16 |
백준2109 - 순회강연 (0) | 2020.07.08 |
백준1062 - 가르침 (0) | 2020.07.06 |