公式

A - Trimo 解説 by en_translator


For beginners

There are various possible approaches; we will introduce one of them.
The problem can be solved by printing characters according to the following logic:

  • Inspect the character from the beginning.
    • If the current character is o, and if the flag is set, print that character.
    • If the current character is not o, set the flag, and print that character.

This way, we can avoid printing any character until we encounter the first character from the beginning that is not o, and print o once such a character is found.

Sample code (C++):

#include<bits/stdc++.h>

using namespace std;

int main(){
  int n;
  string s;
  bool flag=false;
  cin >> n >> s;
  for(auto &nx : s){
    if(nx=='o'){
      if(flag){
        cout << nx;
      }
    }
    else{
      flag=true;
      cout << nx;
    }
  }
  cout << "\n";
  return 0;
}

投稿日時:
最終更新: