Advertisement
Spocoman

2. Find

Jan 29th, 2024
881
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4.  
  5. using namespace std;
  6.  
  7. bool isFound(map<string, string>& m, string& s) {
  8.     for (auto it = m.begin(); it != m.end(); it++) {
  9.         if (it->first == s) {
  10.             return true;
  11.         }
  12.     }
  13.     return false;
  14. }
  15.  
  16. int main()
  17. {
  18.     string line, name, id;
  19.  
  20.     map<string, string> companies = {};
  21.  
  22.     while (true) {
  23.         getline(cin, line);
  24.         if (line == "end") {
  25.             break;
  26.         }
  27.         name = line.substr(0, line.find(' '));
  28.         id = line.substr(line.find(' ') + 1);
  29.  
  30.         companies.insert({ id, name });
  31.     }
  32.  
  33.     cin >> id;
  34.  
  35.     printf(!isFound(companies, id) ? "[not found]\n" : "%s %s\n", companies[id].c_str(), id.c_str());
  36.  
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement