728x90
문제 1193번
https://www.acmicpc.net/problem/1193
1193번: 분수찾기
첫째 줄에 X(1 ≤ X ≤ 10,000,000)가 주어진다.
www.acmicpc.net
오늘 문제를 보니까 이해가 안 돼서 다른 분의 풀이를 보며 공부하였다.
const readFileSyncAdress = process.platform === 'linux' ? '/dev/stdin':'./input.txt'
const input = require("fs").readFileSync(readFileSyncAdress).toString().trim();
let num=Number(input);
let count=1;
while(true){
num-=count;
if(num<=0){
num+=count;
break;
}
count++;
}
if(count%2===1){
console.log(`${count-(num-1)}/${1+(num-1)}`)
}else{
console.log(`${1+(num-1)}/${count-(num-1)}`)
}
[참고] https://codingmyoni.tistory.com/entry/%EB%B0%B1%EC%A4%80-1193-%EB%B6%84%EC%88%98%EC%B0%BE%EA%B8%B0-javascript
728x90
'백준 > JavaScript' 카테고리의 다른 글
[JS] 백준 24263번 - 알고리즘의 수행 시간 2 (4) | 2024.03.12 |
---|---|
[JS] 백준 24262번 - 알고리즘의 수행 시간 1 (0) | 2024.03.10 |
[JS] 백준 2869번 - 달팽이는 올라가고 싶다 (2) | 2024.03.09 |
[JS] 백준 3009번 - 네 번째 점 (0) | 2024.03.03 |
[JS] 백준 기하 - 1085번 (1) | 2024.02.11 |