fork download
  1. #include <iostream>
  2. #include<queue>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int n,t;
  8. char word[51];
  9. cin>>n>>t;
  10.  
  11. for(int i=0;i<n;i++)
  12. {
  13. cin>>word[i];
  14.  
  15. }
  16. while(t--)
  17. {
  18. int j=0;
  19. for(int i=0;i<n;i++)
  20. {
  21. if(word[j]=='B' && word[j+1]=='G')
  22. {
  23. swap(word[j],word[j+1]);
  24. j+=2;
  25.  
  26. }else
  27. j++;
  28.  
  29. }
  30. }
  31. for(int i=0;i<n;i++)
  32. cout<<word[i];
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 4368KB
stdin
5 1
BGGBG
stdout
GBGGB