"JS10 Day 6: Bitwise Operators"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
9번째 줄: 9번째 줄:
----
----


<source lang='javascript'>
<syntaxhighlight lang='javascript'>
'use strict';
'use strict';


33번째 줄: 33번째 줄:
     return inputString[currentLine++];
     return inputString[currentLine++];
}
}
</source>
</syntaxhighlight>
<source lang='javascript'>
<syntaxhighlight lang='javascript'>
function getMaxLessThanK(n, k) {
function getMaxLessThanK(n, k) {
     let max = 0;
     let max = 0;
47번째 줄: 47번째 줄:
     return max;
     return max;
}
}
</source>
</syntaxhighlight>
<source lang='javascript'>
<syntaxhighlight lang='javascript'>
function main() {
function main() {
     const q = +(readLine());
     const q = +(readLine());
58번째 줄: 58번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>

2020년 11월 2일 (월) 02:52 기준 최신판

개요[ | ]

JS10 Day 6: Bitwise Operators
해커랭크 10 Days of Javascript
# 문제 비고
6-7 Day e
18 JS10 Day 6: Bitwise Operators
19 JS10 Day 6: JavaScript Dates
20 JS10 Day 7: Regular Expressions I
21 JS10 Day 7: Regular Expressions II
22 JS10 Day 7: Regular Expressions III

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    
    main();    
});

function readLine() {
    return inputString[currentLine++];
}
function getMaxLessThanK(n, k) {
    let max = 0;
    let result;
    for(let i=1; i<n; i++) {
        for(let j=i+1; j<=n; j++) {
            result = i & j;
            if( result >= k ) continue;
            if( result > max ) max = result;
        }
    }
    return max;
}
function main() {
    const q = +(readLine());
    
    for (let i = 0; i < q; i++) {
        const [n, k] = readLine().split(' ').map(Number);
        
        console.log(getMaxLessThanK(n, k));
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}