0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

競プロ日記#25/07/21

0
Posted at

AtCoder

AtCoder Beginner Contest 394

C - Debug

  • n度目の挑戦。アプローチはわかっていたが実装ができなかった
  • 解説実装
  • for文を使いそうになるが文字列のカーソル位置変数を用意してwhile文でループするのがよさそう

int main() {
    string S;
    cin >> S;
    
    long long N = S.length();
    long long cursor = 0; // 文字列のカーソル位置をこれで管理する

    while(cursor < N - 1){
        if ((S[cursor] == 'W') && (S[cursor + 1] == 'A')){
            S[cursor] = 'A';
            S[cursor + 1] = 'C';
            if (cursor > 0){
                cursor--;
            }
        }else{
            cursor++;
        }
    }
    cout << S << endl;
    return 0;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?