๋ฌธ์
์ปดํจํฐ๋ฅผ ์ด์ฉํ๋ฉด ์ํ ๊ณ์ฐ์ด ์กฐ๊ธ ์ฌ์์ง๋ค. ๋ค์๊ณผ ๊ฐ์ ์๋ฅผ ์ดํด๋ณด์. ์ธ ๋ณ์ ๊ธธ์ด๊ฐ a, b, c(c๋ ๋น๋ณ)์ด๋ฉด์ a2+b2=c2๋ฅผ ๋ง์กฑํ๋ ์ผ๊ฐํ์ ์ง๊ฐ์ผ๊ฐํ์ด๋ผ๊ณ ํ๋ค. ์ด ๊ณต์์ ํผํ๊ณ ๋ผ์ค์ ๋ฒ์น์ด๋ผ๊ณ ํ๋ค.
์ง๊ฐ ์ผ๊ฐํ์ ๋ ๋ณ์ ๊ธธ์ด๊ฐ ์ฃผ์ด์ก์ ๋, ํ ๋ณ์ ๊ธธ์ด๋ฅผ ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค.

์ ์ถ๋ ฅ ์์

ํด๊ฒฐ
const fs = require('fs');
const { start } = require('repl');
const stdin = (process.platform === 'linux'
? fs.readFileSync('/dev/stdin').toString()
: `6 -1 6
3 4 -1
-1 2 7
5 -1 3
0 0 0`
).match(/[^\r\n]+/g);
const input = (() => {
let line = 0;
return () => stdin[line++];
})();
let i = 1;
let answer=[];
while (true) {
const s = input().split(' ').map(Number)
if (s[0] === 0) break;
const area = s.indexOf(-1)
const arr = ['a','b','c']
if (arr[area] == 'a') {
const sq = (s[2]**2) - (s[1]**2)
const line = (Math.sqrt(sq)).toFixed(3)
if (line < s[2] && line != 0){
answer.push(`Triangle #${i}\n${arr[area]} = ${line}`)
} else {
answer.push(`Triangle #${i}\nImpossible.`)
}
}
if (arr[area] == 'b') {
const sq = (s[2]**2) - (s[0]**2)
const line = (Math.sqrt(sq)).toFixed(3)
if (line < s[2] && line != 0){
answer.push(`Triangle #${i}\n${arr[area]} = ${line}`)
} else {
answer.push(`Triangle #${i}\nImpossible.`)
}
}
if (arr[area] == 'c') {
const sq = (s[0]**2) + (s[1]**2)
const line = (Math.sqrt(sq)).toFixed(3)
if (line > s[2] && line != 0){
answer.push(`Triangle #${i}\n${arr[area]} = ${line}`)
} else {
answer.push(`Triangle #${i}\nImpossible.`)
}
}
i++;
}
console.log(answer.join('\n\n'))
'๊ฐ๋ฐ ๊ณต๋ถ > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค/Node.js] ์ค๋๋ ์ก๋ค (0) | 2023.03.23 |
---|---|
[๋ฐฑ์ค/Node.js] ๋ธ๋์ญ (0) | 2023.03.22 |
[๋ฐฑ์ค/Node.js] ํฌ๊ทธ๋จ (0) | 2023.03.20 |
[๋ฐฑ์ค/Node.js] ํ์ฐ ์๋ฃ (0) | 2023.03.17 |
[๋ฐฑ์ค/Node.js] ํฐ๋ฆฐ๋๋กฌ์ (0) | 2023.03.16 |