fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <utility>
  4. #include <string>
  5. #include <sstream>
  6. #include <algorithm>
  7.  
  8. int main()
  9. {
  10. std::vector<std::pair<std::string, int>> phoneBook;
  11.  
  12. int n;
  13. std::string line;
  14.  
  15. std::getline(std::cin, line);
  16. std::istringstream(line) >> n;
  17.  
  18. for (int i = 0; i < n; ++i)
  19. {
  20. std::getline(std::cin, line);
  21. std::string name;
  22. int phoneNumber;
  23. std::istringstream(line) >> name >> phoneNumber;
  24. phoneBook.push_back(std::make_pair(name, phoneNumber));
  25. }
  26.  
  27. while (std::getline(std::cin, line))
  28. {
  29. auto iter = std::find_if(phoneBook.begin(), phoneBook.end(),
  30. [&](const std::pair<std::string, int> &entry){
  31. return (entry.first == line);
  32. }
  33. );
  34. if (iter != phoneBook.end())
  35. std::cout << iter->first << "=" << iter->second << std::endl;
  36. else
  37. std::cout << "Not found" << std::endl;
  38. }
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 4396KB
stdin
3
sam 99912222
tom 11122222
harry 12299933
sam
edward
harry
stdout
sam=99912222
Not found
harry=12299933