-2
int n,t;
cin>>n>>t;
char arr[n];
for(int i=0;i<n;i++){
    cin>>arr[i];
}
// for(int i=0;i<n;i++){
//     cout<<arr[i];
// }
while(t>0){
    for(int i=0;i<n-1;i++){
        if((arr[i]=='B')&&(arr[i+1]=='G')){
            char temp = arr[i];
            arr[i] = arr[i+1];
            arr[i+1] = arr[i];
            i++;
        }
    }
    --t;
}
for(int i=0;i<n;i++){
    cout<<arr[i]<<" ";
}

I am getting one extra % sign while printing the output Like if input is BGGBG output is appearing as GGBGB%

Dexter
  • 21
  • 1
  • 6

1 Answers1

2

The extra "%" is not something printed by your program. It is just something that your shell added to tell you that there is no newline character after the text.

In order to easily check this you can redirect your program output to a file. You will see that the "%" character will not be in the file.

Alternatively, if you print a newline at the end of your program you will not see the "%" character in your shell.

darcamo
  • 3,294
  • 1
  • 16
  • 27