반응형
    
    
    
  
                              Notice
                              
                          
                        
                          
                          
                            Recent Posts
                            
                        
                          
                          
                            Recent Comments
                            
                        
                          
                          
                            Link
                            
                        
                    | 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 | 
| 12 | 13 | 14 | 15 | 16 | 17 | 18 | 
| 19 | 20 | 21 | 22 | 23 | 24 | 25 | 
| 26 | 27 | 28 | 29 | 30 | 31 | 
                            Tags
                            
                        
                          
                          - 자바스크립트
- 소켓
- type challenge
- Crawling
- dfs
- Node.js
- 문자열
- TCP
- 쉬운 문제
- 백준
- typescript
- dp
- BFS
- 크롤링
- 레벨 1
- Algorithm
- HTTP 완벽 가이드
- socket
- 알고리즘
- Nestjs
- 프로그래머스 레벨 2
- ip
- 가천대
- javascript
- 타입스크립트
- 타입 챌린지
- 수학
- 프로그래머스
- HTTP
- 그래프
                            Archives
                            
                        
                          
                          - Today
- Total
kakasoo
[node.js] 일곱 난쟁이 ( 백준 2309번 ) 본문
반응형
    
    
    
  귀찮아서 때려 박듯이 풀었다.
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});
const people = [];
rl.on("line", (line) => {
    people.push(line);
    if (people.length === 9) {
        main(people);
    }
});
/**
 *
 * @param {string[]} people
 */
const main = (people) => {
    const heights = people.map(Number).sort((a, b) => a - b);
    const sum = heights.reduce((acc, cur) => acc + cur);
    const minus = sum - 100;
    let check1, check2;
    for (let i = 0; i < 8; i++) {
        for (let j = i + 1; j < 9; j++) {
            if (heights[i] + heights[j] === minus) {
                [check1, check2] = [i, j];
            }
        }
    }
    for (let i = 0; i < 9; i++) {
        if (i !== check1 && i !== check2) {
            console.log(heights[i]);
        }
    }
};
반응형
    
    
    
  '프로그래밍 > 알고리즘 풀이' 카테고리의 다른 글
| [node.js] 크레인 인형 뽑기 ( 프로그래머스 레벨1 ) (0) | 2021.06.25 | 
|---|---|
| [node.js] 날짜 계산 ( 백준 1476번 ) (0) | 2021.05.12 | 
| [node.js] 곱셈 ( 백준 1629번 ) (0) | 2021.05.11 | 
| [node.js] 요세푸스 문제 ( 백준 1158번 ) (0) | 2021.04.16 | 
| [node.js] 트리의 부모 찾기 ( 백준 11725번 ) (0) | 2021.04.15 | 
 
                   
                   
                  