본문 바로가기
코딩테스트/백준

1076. 저항 - Node.js

by MiteDev 2024. 9. 12.

const fs = require('fs');
const file_path = process.platform === 'linux' ? 'dev/stdin' : `${__dirname}/input.txt`
const input = fs.readFileSync(file_path).toString().trim().replace(/\r/g, '').split('\n');


/**
 * @param {string} input 
 * @returns 
 */
const solution = (input) => {
    const [f_key, s_key, pow_key] = input;
    const resistance = ['black', 'brown', 'red', 'orange', 'yellow', 'green', 'blue', 'violet', 'grey', 'white'];

    const f = resistance.indexOf(f_key);
    const s = resistance.indexOf(s_key);
    const pow = resistance.indexOf(pow_key);

    const multiplicand = Number(`${f}${s}`);
    const multiplier = Math.pow(10, pow);

    const result = multiplicand * multiplier;

    return result;
}

console.log(solution(input));

'코딩테스트 > 백준' 카테고리의 다른 글

1159. 농구 경기 - Node.js  (1) 2024.09.14
1152. 단어의 개수 - Node.js  (0) 2024.09.14
1100. 하얀 칸 - Node.js  (0) 2024.09.14
1075. 나누기 - Node.js  (0) 2024.09.12
1009. 분산처리 - Node.js  (0) 2024.09.12