1process.stdin.resume(); 2process.stdin.setEncoding('utf-8'); 3let input = ''; 4 5process.stdin.on('data', (data) => { 6 input += data; 7}); 8 9process.stdin.on('end', () => { 10 // 将输入的一连串正整数数组转换为数组形式 11 let inputArray = input.trim().split(' ').map(Number); 12 13 /** 14 * 待实现函数,在此函数中填入答题代码 15 */ 16 function doFunc() { 17 let heights = inputArray; 18 let expected = [...heights].sort((a, b) => a - b); // 非递减排序得到预期数组 19 20 let mismatchCount = 0; 21 for (let i = 0; i < heights.length; i++) { 22 if (heights[i] !== expected[i]) { 23 mismatchCount++; 24 } 25 } 26 27 console.log(mismatchCount); 28 } 29 30 doFunc(); 31 process.exit(); 32});
Copyright ©2010-2022 比特日记 All Rights Reserved.
Powered By 可尔物语