字符串转换后长度

字符串转换后长度

 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});
process.stdin.resume(); process.stdin.setEncoding('utf-8'); let input = ''; process.stdin.on('data', (data) => { input += data; }); process.stdin.on('end', () => { let inputArray = input.split('\n'); let s = inputArray[0]; let t = parseInt(inputArray[1], 10); /** * 执行字符转换的函数 */ function transformChar(char) { if (char === 'z') { return 'ab'; } else { return String.fromCharCode(char.charCodeAt(0) + 1); } } /** * 执行 t 次转换并返回最终字符串的长度 */ function doFunc() { let result = s; for (let i = 0; i < t; i++) { let newResult = ''; for (let j = 0; j < result.length; j++) { newResult += transformChar(result[j]); } result = newResult; } return result.length; } console.log(doFunc()); process.exit(); });

Powered By 可尔物语

浙ICP备11005866号-12