Last active
January 6, 2021 12:33
-
-
Save somedaycode/8eec09f680cb19163405a60f1741b5f7 to your computer and use it in GitHub Desktop.
코드스쿼드_알고리즘_week1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const readline = require('readline'); | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}); | |
const input = []; | |
rl.on('line', function (line) { | |
input.push(line.split(' ')); | |
rl.close(); | |
}).on('close', function () { | |
const inputs = input.pop(); | |
const result = inputs.map((v) => v.split('')); | |
const a = result[0].reverse(); | |
const b = result[1].reverse(); | |
let longNumber, shortNumber; | |
longNumber = a.length > b.length ? a : b; | |
shortNumber = a.length < b.length ? a : b; | |
const tempAnswer = []; | |
let carry = 0; | |
let i = 0; | |
//short length | |
for (; i < shortNumber.length; i++) { | |
let sum = Number(a[i]) + Number(b[i]) + carry; | |
if (sum >= 10) { | |
sum = sum - 10; | |
carry = 1; | |
} else carry = 0; | |
tempAnswer.push(sum); | |
} | |
// rest numbers + answer | |
for (; i < longNumber.length; i++) { | |
let sum = Number(longNumber[i]) + carry; | |
if (sum >= 10) { | |
sum = sum - 10; | |
carry = 1; | |
} else carry = 0; | |
tempAnswer.push(sum); | |
} | |
if (carry) tempAnswer.push(1); | |
const answer = tempAnswer.reverse().join(''); | |
console.log(answer); | |
process.exit(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const readline = require('readline'); | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}); | |
let round = 0; | |
const arr = []; | |
rl.on('line', function (line) { | |
if (!round) { | |
round = +line; | |
} else { | |
arr.push(line.split(' ')); | |
if (arr.length === round) { | |
rl.close(); | |
} | |
} | |
}).on('close', function () { | |
const newArr = arr.map((v) => { | |
const a = v[0]; | |
const b = v[1]; | |
let result = a; | |
for (let i = 1; i < b; i++) { | |
result = (result * a) % 10; | |
} | |
return result; | |
}); | |
for (let i = 0; i < round; i++) { | |
newArr[i] === 0 ? console.log(10) : console.log(newArr[i]); | |
} | |
process.exit(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const readline = require('readline'); | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}); | |
const color = [ | |
'black', | |
'brown', | |
'red', | |
'orange', | |
'yellow', | |
'green', | |
'blue', | |
'violet', | |
'grey', | |
'white', | |
]; | |
const input = []; | |
rl.on('line', function (line) { | |
input.push(line); | |
if (input.length === 3) rl.close(); | |
}).on('close', function () { | |
const num = 10; | |
const result = input.map((v) => { | |
for (let i = 0; i < color.length; i++) { | |
if (v === color[i]) return color.indexOf(color[i]); | |
} | |
}); | |
function answer(result) { | |
result[0] = result[0] * num; | |
result[2] = result[2] === 0 ? 1 : 10 ** result[2]; | |
return (result[0] + result[1]) * result[2]; | |
} | |
console.log(answer(result)); | |
process.exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment