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 const trimmedInput = input.trim(); 12 13 // 实现查找最长元音子串长度的函数 14 function findLongestVowelSubstringLength(str) { 15 const vowels = new Set(['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']); 16 let maxLength = 0; 17 let currentLength = 0; 18 19 for (let char of str) { 20 if (vowels.has(char)) { 21 // 如果是元音字母,增加当前元音子串的长度 22 currentLength++; 23 // 更新最长元音子串的长度 24 maxLength = Math.max(maxLength, currentLength); 25 } else { 26 // 如果不是元音字母,重置当前元音子串的长度 27 currentLength = 0; 28 } 29 } 30 31 return maxLength; 32 } 33 34 // 调用函数并输出结果 35 const result = findLongestVowelSubstringLength(trimmedInput); 36 console.log(result); 37 38 process.exit(); 39});
Copyright ©2010-2022 比特日记 All Rights Reserved.
Powered By 可尔物语