1process.stdin.resume(); 2process.stdin.setEncoding('utf-8'); 3let input = ''; 4process.stdin.on('data', (data) => { 5 input += data; 6}); 7process.stdin.on('end', () => { 8 let inputArray = input.split('\n'); 9 let s = inputArray[0]; 10 let t = parseInt(inputArray[1], 10); 11 12 /** 13 * 执行字符转换的函数 14 */ 15 function transformChar(char) { 16 if (char === 'z') { 17 return 'ab'; 18 } else { 19 return String.fromCharCode(char.charCodeAt(0) + 1); 20 } 21 } 22 23 /** 24 * 执行 t 次转换并返回最终字符串的长度 25 */ 26 function doFunc() { 27 let result = s; 28 for (let i = 0; i < t; i++) { 29 let newResult = ''; 30 for (let j = 0; j < result.length; j++) { 31 newResult += transformChar(result[j]); 32 } 33 result = newResult; 34 } 35 return result.length; 36 } 37 38 console.log(doFunc()); 39 process.exit(); 40});
Copyright ©2010-2022 比特日记 All Rights Reserved.
Powered By 可尔物语