티스토리 뷰
https://www.acmicpc.net/problem/6603
6603번: 로또
입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 한 줄로 이루어져 있다. 첫 번째 수는 k (6 < k < 13)이고, 다음 k개 수는 집합 S에 포함되는 수이다. S의 원소는 오름차순으로
www.acmicpc.net
const fs = require('fs');
const input = fs.readFileSync("./dev/stdin").toString().trim().split("\n").map(v=>v.split(' ').map(x=>+x));
input.pop();
const answer = [];
input.forEach(v=>{
let result = [];
if(answer.length>0) answer.push([])
const N = +v.shift();
for(let i =0; i<1<<N; i++){
if(countBits(i)==6){
let temp = [];
let value = i;
for(let j = 0; j<N; j++){
if((value&1)==1) temp.push(v[j]);
value = value>>1;
}
result.push(temp)
}
}
answer.push(sortSix(result))
})
function countBits(value){
let count = 0;
while(value>0){
if((value&1)==1) count++;
value = value>>1;
}
return count;
}
console.log(answer.join('\n'))
function sortSix(arr){
return arr.sort((a,b)=>{
if(a[0]>b[0]){
return 1
}else if(a[0]<b[0]){
return -1
}else{
if(a[1]>b[1]){
return 1
}else if(a[1]<b[1]){
return -1
}else{
if(a[2]>b[2]){
return 1
}else if(a[2]<b[2]){
return -1
}else{
if(a[3]>b[3]){
return 1
}else if(a[3]<b[3]){
return -1
}else{
if(a[4]>b[4]){
return 1
}else if(a[4]<b[4]){
return -1
}else{
if(a[5]>b[5]){
return 1
}else if(a[5]<b[5]){
return -1
}
}
}
}
}
}
}).map(v=>v.join(' ')).join('\n')
}
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js)백준 9095번: 1, 2, 3 더하기 (0) | 2021.12.21 |
---|---|
Node.js)백준 1182: 부분수열의 합 (0) | 2021.12.21 |
Node.js) 백준 10867번: 중복 빼고 정렬하기 (0) | 2021.12.21 |
Node.js)백준 11651번 : 좌표 정렬하기2 (0) | 2021.12.21 |
Node.js)백준 11650번 : 좌표 정렬하기 (0) | 2021.12.21 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 서버개발
- 그래프
- create databases;
- DB 생성
- 투포인터 연습
- MOD
- 은둔청년체험
- 다이나밍프로그래밍
- 다이나믹프로그래밍
- 개발자면접
- 로드나인
- 동적프로그래밍
- create db
- MySQL
- BFS
- node.js
- 투포인터
- 면접질문
- 서버점검
- 롱베케이션
- 면접비
- 최소공통조상
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함