HackerEarth에서 문제를 해결하는 사람이 있습니까? 나는 그들이 입력 데이터를 제공하는 방식과 혼동됩니다.
나는 지금까지 Leetcode를 사용하여 문제를 해결해 왔고 나는 그것들에 꽤 만족하지만 불행히도 어떤 사람들은 코딩 과제를 호스팅하기 위해 HackerEarth를 선호하고 입력 테스트 케이스를 올바르게 읽으려고 노력하는 데 문제가 있습니다.
내 조사를 수행 한 결과 잘못된 정보가있는 "솔루션 가이드"를 찾았습니다. https://www.hackerearth.com/docs/wiki/developers/solution-guide/
어떻게 개별 줄을 읽고 결과를 JS (Node v10) 판단으로 출력합니까?
감사합니다.
방금 로그인하여 여기에서 찾아 보았습니다 .
내가 좋아하지 않는 HackerRank와 비슷한 것 같습니다. (LeetCode의 UI는 재미 있고 사용하기 훨씬 쉽습니다.)
LeetCode에서는 출력 할 필요가 없습니다. 여기서 출력을 출력해야하는 것 같습니다 (예를 들어 JavaScript에서는 console.log
메서드 내부에서 인쇄하는 것은 일반적으로 나쁜 코딩 방식이라는 것을 언급하지 않고 사용합니다 ).
이 솔루션 (해당 활동 중 하나에서 복사)은 문제를 파악할 수있는 기준으로 통과하는 것 같습니다.
/*
// Sample code to perform I/O:
process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";
process.stdin.on("data", function (input) {
stdin_input += input; // Reading input from STDIN
});
process.stdin.on("end", function () {
main(stdin_input);
});
function main(input) {
process.stdout.write("Hi, " + input + ".\n"); // Writing output to STDOUT
}
// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
*/
// Write your code here
process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";
process.stdin.on("data", function (input) {
stdin_input += input;
});
process.stdin.on("end", function () {
main(stdin_input);
});
function main(input) {
input = input.split('\n');
input.shift();
input.forEach(n => {
n = parseInt(n);
let fact = BigInt(1);
while(n){
fact = BigInt(fact) * BigInt(n);
n--;
}
console.log(String(fact).replace('n',''));
});
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다