Official

B - Daily Cookie 2 Editorial by yuto1115

解説

「現在の \(S\) の中で最も右の位置にある @ を探し、それを . に置き換える」という処理を \(D\) 回行えばよいです。

具体的な実装方法は下記の実装例 (C++, Python) を参考にしてください。

実装例 (C++) :

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, d;
    string s;
    cin >> n >> d >> s;
    for (int i = 0; i < d; i++) {
        for (int j = n - 1; j >= 0; j--) {
            if (s[j] == '@') {
                s[j] = '.';
                break;
            }
        }
    }
    cout << s << endl;
}

実装例 (Python) :

n, d = map(int, input().split())
s = input()
for i in range(d):
    for j in range(n):
        if s[n - 1 - j] == '@':
            s = s[:n - 1 - j] + "." + s[n - j:]
            break
print(s)

posted:
last update: