Restore original String from given Encrypted String by the given operations | C ++ Program to implement the above approach ; Function to decrypt and print the original strings ; If length is exceeded ; Reverse the string ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int decryptString ( string s , unsigned int N ) { for ( unsigned int i = 0 ; i < s . size ( ) ; i += 2 * N ) { auto end = s . begin ( ) + i + N ; if ( i + N > s . size ( ) ) end = s . end ( ) ; reverse ( s . begin ( ) + i , end ) ; } cout << s << endl ; } int main ( ) { string s = " ihTs ▁ suohld ▁ ebeas ! y " ; unsigned int N = 3 ; decryptString ( s , N ) ; return 0 ; }