fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define MM ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
  4. int main() {
  5. MM
  6. int t;
  7. cin>>t;
  8. vector<string> st;
  9. while(t--) {
  10. string s;
  11. cin>>s;
  12. st.push_back(s);
  13. }
  14. int f=1;
  15. vector<string> v;
  16. for(int i=st.size()-1;i>=0;i--) {
  17. if (f) {
  18. v.push_back(st[i]);
  19. f=0;
  20. }
  21. else {
  22. auto it = find(v.begin(),v.end(),st[i]);
  23. if (it == v.end()) {
  24. v.push_back(st[i]);
  25. }
  26. }
  27. }
  28. for(int i=0;i<v.size();i++) {
  29. cout<<v[i]<<'\n';
  30. }
  31. }
Success #stdin #stdout 0.01s 5288KB
stdin
4
alex
ivan
roman
ivan
stdout
ivan
roman
alex