728x90
반응형

백준알고리즘

- Bronze 5 -

 #15439. Vera and Outfits by JAVA and node.js 

 


 

문제

출처: https://www.acmicpc.net/problem/15439 

 

이제 영어 문제는 두렵지 않다.(구글 번역기 힘줘..!)


 

접근 방법

단순 순열 문제다.

n개의 컬러, n개의 상의, n개의 하의인데,

상의를 선택할 가지수는 n가지이고, 하의는 같은 색을 제외한 (n-1)가지이다.

따라서 Vera가 좋아할 경우의 수는 n*(n-1)이다.

 


 

풀이

▶ JAVA

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        scan.close();
        System.out.println(n * (n-1));
    }
}

 

▶ node.js

var fs = require('fs');
var input = fs.readFileSync('/dev/stdin').toString().trim();
console.log(input * (input-1));

 


 

결과

 

 

퇴근해야지!


 

 

 

 

 

End.

heisely's 괴발개발 개발일지

 

728x90
반응형

+ Recent posts