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 const [s, kStr] = input.trim().split('\n'); 11 const k = parseInt(kStr, 10); 12 13 function countSubstrings(str, k) { 14 const n = str.length; 15 let count = 0; 16 17 for (let i = 0; i < n; i++) { 18 const charCount = {}; 19 for (let j = i; j < n; j++) { 20 const char = str[j]; 21 charCount[char] = (charCount[char] || 0) + 1; 22 if (Object.values(charCount).some(val => val >= k)) { 23 count++; 24 } 25 } 26 } 27 28 return count; 29 } 30 31 console.log(countSubstrings(s, k)); 32 33 process.exit(); 34});
Copyright ©2010-2022 比特日记 All Rights Reserved.
Powered By 可尔物语