searching the first character left of index k and not equal to greatest character of the string
for ( int i = k - 1 ; i >= 0 ; i -- ) { if ( s [ i ] != v [ v . size ( ) - 1 ] ) { for ( int j = 0 ; j < i ; j ++ ) { cout << s [ j ] ; }