text: Generate a string whose all K | C ++ program to generate a string whose substrings of length K concatenates to form given strings ; Function to return the required required string ; Iterate the given string ; Append the first character of every substring of length K ; Consider all characters from the last substring ; Driver Program
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; void decode_String ( string str , int K ) { string ans = " " ; for ( int i = 0 ; i < str . size ( ) ; i += K ) ans += str [ i ] ; for ( int i = str . size ( ) - ( K - 1 ) ; i < str . size ( ) ; i ++ ) ans += str [ i ] ; cout << ans << endl ; } int main ( ) { int K = 3 ; string str = " abcbcscsesesesd " ; decode_String ( str , K ) ; }