Advertisement
Spocoman

04. Record Unique Names

Jan 21st, 2024
1,007
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. bool isfound(vector<string> v, string s) {
  8.     for (size_t i = 0; i < v.size(); i++) {
  9.         if (v[i] == s) {
  10.             return true;
  11.         }
  12.     }
  13.     return false;
  14. }
  15.  
  16. int main() {
  17.     int n;
  18.     cin >> n;
  19.  
  20.     vector<string> names;
  21.  
  22.     string name;
  23.  
  24.     for (int i = 0; i < n; i++) {
  25.         cin >> name;
  26.         if (!isfound(names, name)) {
  27.             names.push_back(name);
  28.         }
  29.     }
  30.  
  31.     for (auto& name : names) {
  32.         cout << name << endl;
  33.     }
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement