Find the arrangement of queue at given time | CPP program to find the arrangement of queue at time = t ; prints the arrangement at time = t ; Checking the entire queue for every moment from time = 1 to time = t . ; If current index contains ' B ' and next index contains ' G ' then swap ; Driver function for the program
#include <bits/stdc++.h> NEW_LINE using namespace std ; void solve ( int n , int t , string s ) { for ( int i = 0 ; i < t ; i ++ ) for ( int j = 0 ; j < n - 1 ; j ++ ) if ( s [ j ] == ' B ' && s [ j + 1 ] == ' G ' ) { char temp = s [ j ] ; s [ j ] = s [ j + 1 ] ; s [ j + 1 ] = temp ; j ++ ; } cout << s ; } int main ( ) { int n = 6 , t = 2 ; string s = " BBGBBG " ; solve ( n , t , s ) ; return 0 ; }