Generate a sequence with the given operations | C ++ Implementation of above approach ; function to find minimum required permutation ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void StringMatch ( string s ) { int lo = 0 , hi = s . length ( ) , len = s . length ( ) ; vector < int > ans ; for ( int x = 0 ; x < len ; x ++ ) { if ( s [ x ] == ' I ' ) { ans . push_back ( lo ) ; lo += 1 ; } else { ans . push_back ( hi ) ; hi -= 1 ; } } ans . push_back ( lo ) ; cout << " [ " ; for ( int i = 0 ; i < ans . size ( ) ; i ++ ) { cout << ans [ i ] ; if ( i != ans . size ( ) - 1 ) cout << " , " ; } cout << " ] " ; } int main ( ) { string S = " IDID " ; StringMatch ( S ) ; return 0 ; }