Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #ifndef PARSE_COMPANIES_H
  2. #define PARSE_COMPANIES_H
  3.  
  4. #include "Company.h"
  5.  
  6. #include <bits/stdc++.h>
  7. using namespace std;
  8.  
  9. bool is_in(string str, vector <string> vec)
  10. {
  11. for (int i = 0; i != vec.size(); i ++)
  12. {
  13. if (str == vec[i])
  14. {
  15. return true;
  16. }
  17. }
  18. return false;
  19. }
  20.  
  21. Company *parseUniqueCompanies(string input, int &numCompanies, string (*criterea)(const Company &c))
  22. {
  23. numCompanies = 0;
  24.  
  25. stringstream ss(input);
  26. string name, str_id;
  27.  
  28. vector <pair <int, string>> company_details;
  29. vector <string> critereas;
  30. while(ss >> str_id, ss >> name)
  31. {
  32. const Company *com = new Company(stoi(str_id), name);
  33. string str = criterea(*com);
  34. delete com;
  35. if (!is_in(str, critereas))
  36. {
  37. critereas.push_back(str);
  38. numCompanies ++;
  39. company_details.push_back({stoi(str_id), name});
  40. }
  41. };
  42.  
  43. Company *companies = new Company[numCompanies];
  44.  
  45. for (int i = 0; i != numCompanies; i ++)
  46. {
  47. Company *tmp = new Company(company_details[i].first, company_details[i].second);
  48. companies[i] = *tmp;
  49. delete tmp;
  50. }
  51.  
  52. return companies;
  53. }
  54.  
  55. #endif // !PARSE_COMPANIES_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement