Official

B - Qual B Editorial by physics0523


サンプルの説明文のような流れを素直に実装するとこの問題に正解することができます。
具体的には、文字列を前から見て先頭から \(K+1\) 個目以降の ox に書き換えることになります。

実装例 (C++):

#include<bits/stdc++.h>

using namespace std;

int main(){
  int n,k;
  string s;
  cin >> n >> k >> s;
  for(auto &nx : s){
    if(nx=='o'){
      if(k<=0){nx='x';}
      k--;
    }
  }
  cout << s << "\n";
  return 0;
}

posted:
last update: