Thấy bạn đề tag C++ mà mình thấy ngại. Regex trong C++ vẫn phải xử lí với while nên mình xài Python cho tiết kiệm calo.
import re
s = input()
k = input()
# xem xâu s có k kí tự liên tiếp hay không
# Demo regex: https://regex101.com/r/fuyA4s/4
print(re.findall("((?P<ch>[a-z])(?P=ch){"+k+"})", s) != list())
# xâu s mới
# Demo regex: https://regex101.com/r/fuyA4s/1
new_s = ''.join(re.findall("(?P<ch>[a-z])(?P=ch)*", s))
print(new_s)
Run online: