公式

D - Daily Cookie 2 解説 by en_translator


It is sufficient to do the following operation \(D\) times: find the rightmost @ in \(S\), and replace it with ..

For more details on implementation, please refer to the sample code below (C++ and Python).

Sample code (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;
}

Sample code (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)

投稿日時:
最終更新: