Official

B - 上書き/Overwrite Editorial by tatyam


\(N ≤ 100\) なので、 for 文などを使って処理を問題文の通りに実装すると正解を得ることができます。

回答例 (C++)

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(){
    int n;
    string s, t;
    cin >> n >> s;
    for(char c : s){
        t.erase(remove(t.begin(), t.end(), c), t.end());
        t += c;
    }
    cout << t << endl;
}

回答例 (Python)

n = int(input())
s = input()
t = ""
for c in s:
    t = t.replace(c, "") + c
print(t)

posted:
last update: