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 let inputArray = input.trim().split(' '); 11 // 调用 doFunc 函数计算和为 100 的整数对数量 12 let result = doFunc(inputArray); 13 console.log(result); 14 process.exit(); 15}); 16 17function doFunc(numbers) { 18 let pairCount = 0; 19 const n = numbers.length; 20 // 遍历数组,使用两层循环找出所有可能的数对 21 for (let i = 0; i < n; i++) { 22 for (let j = i + 1; j < n; j++) { 23 const num1 = parseInt(numbers[i], 10); 24 const num2 = parseInt(numbers[j], 10); 25 // 检查两数之和是否为 100 26 if (num1 + num2 === 100) { 27 pairCount++; 28 } 29 } 30 } 31 return pairCount; 32}
Copyright ©2010-2022 比特日记 All Rights Reserved.
Powered By 可尔物语