Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef PARSE_COMPANIES_H
- #define PARSE_COMPANIES_H
- #include "Company.h"
- #include <bits/stdc++.h>
- using namespace std;
- bool is_in(string str, vector <string> vec)
- {
- for (int i = 0; i != vec.size(); i ++)
- {
- if (str == vec[i])
- {
- return true;
- }
- }
- return false;
- }
- Company *parseUniqueCompanies(string input, int &numCompanies, string (*criterea)(const Company &c))
- {
- numCompanies = 0;
- stringstream ss(input);
- string name, str_id;
- vector <pair <int, string>> company_details;
- vector <string> critereas;
- while(ss >> str_id, ss >> name)
- {
- const Company *com = new Company(stoi(str_id), name);
- string str = criterea(*com);
- delete com;
- if (!is_in(str, critereas))
- {
- critereas.push_back(str);
- numCompanies ++;
- company_details.push_back({stoi(str_id), name});
- }
- };
- Company *companies = new Company[numCompanies];
- for (int i = 0; i != numCompanies; i ++)
- {
- Company *tmp = new Company(company_details[i].first, company_details[i].second);
- companies[i] = *tmp;
- delete tmp;
- }
- return companies;
- }
- #endif // !PARSE_COMPANIES_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement