高度检查器

高度检查器

 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});
process.stdin.resume(); process.stdin.setEncoding('utf-8'); let input = ''; process.stdin.on('data', (data) => { input += data; }); process.stdin.on('end', () => { // 将输入的一连串正整数数组转换为数组形式 let inputArray = input.trim().split(' ').map(Number); /** * 待实现函数,在此函数中填入答题代码 */ function doFunc() { let heights = inputArray; let expected = [...heights].sort((a, b) => a - b); // 非递减排序得到预期数组 let mismatchCount = 0; for (let i = 0; i < heights.length; i++) { if (heights[i] !== expected[i]) { mismatchCount++; } } console.log(mismatchCount); } doFunc(); process.exit(); });

Powered By 可尔物语

浙ICP备11005866号-12