Generate an N | C ++ program to implement the above approach ; Function to generate a string of length N having longest palindromic substring of length K ; Fill first K characters with ' a ' ; Stores a non - palindromic sequence to be repeated for N - k slots ; Print N - k remaining characters ; Driver Code ; Given N and K
#include <bits/stdc++.h> NEW_LINE using namespace std ; void string_palindrome ( int N , int K ) { for ( int i = 0 ; i < K ; i ++ ) cout << " a " ; string s = " bcd " ; for ( int i = 0 ; i < N - K ; i ++ ) cout << s [ i % 3 ] ; } int main ( ) { int N = 5 , K = 3 ; string_palindrome ( N , K ) ; return 0 ; }