fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define pb push_back
  5. #define nl '\n'
  6. #define py cout << "YES\n"
  7. #define pn cout << "NO\n"
  8. const double eps = 1e-7;
  9.  
  10. void fastio() {
  11. ios_base::sync_with_stdio(false);
  12. cin.tie(nullptr);
  13. cout.tie(nullptr);
  14. }
  15.  
  16. void solve() {
  17. int n; cin >> n;
  18. map<string,int> mp;
  19. for(int i = 0; i < n; i++){
  20. string s; cin >> s;
  21. mp[s]=i;
  22. }
  23.  
  24. vector<pair<int,string>> v;
  25. for(auto it: mp){
  26. v.pb({it.second, it.first});
  27. }
  28. sort(v.rbegin(), v.rend());
  29. for(auto it: v){
  30. cout << it.second << nl;
  31. }
  32.  
  33. }
  34.  
  35. int main() {
  36. fastio();
  37. int t = 1;
  38. //cin >> t;
  39. while (t--)
  40. solve();
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 5320KB
stdin
4
alex
ivan
roman
ivan
stdout
ivan
roman
alex