Editorial for Messenger


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: bamboo881

Lời giải

Đây là môt bài toán đơn giản nếu bạn biết đến STL C++.

Lời giải của mình đưa ra: do thời gian đã được sắp xếp tăng dần nên những người xuất hiện càng ở cuối thì sẽ là người càng xuất hiện ở đầu Messenger. Vấn đề làm sao để đánh dấu biết được người đó mình đã in ra trước đó rồi hay chưa? và ý tưởng sẽ là dùng Map để giải quyết vấn đề này.

Code tham khảo

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n; cin >> n;
    vector<string> a(n);
    for (auto& i : a) cin >> i;
    map<string, bool> ma;
    vector<string> ret;
    for (int i = n - 1; i >= 0; --i)
        if (ma[a[i]] == false) {
            ret.push_back(a[i]);
            ma[a[i]] = true;
        }
    cout << ret.size() << '\n';
    for (auto i : ret) cout << i << '\n';
    return 0;
}

Comments

Please read the guidelines before commenting.


There are no comments at the moment.