Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <map>
  5. #include <queue>
  6.  
  7. using namespace std;
  8.  
  9. struct CompanyStr {
  10. string person_or_company;
  11. int percent;
  12. };
  13.  
  14. class OffShore {
  15. set<string> person;
  16. map<string, vector<CompanyStr>> company;
  17.  
  18. vector<string> all_ownersBFS (string &comp) {
  19. set<string> visited;
  20. vector<string> result;
  21. queue<string> checker;
  22. checker.push(comp);
  23. while (!checker.empty()) {
  24. vector<CompanyStr>::iterator itr; // iterator that runs through in my vector pairs.
  25. string curr = checker.front();
  26. checker.pop();
  27. if (company.find(curr) != company.end() && visited.find(curr) == visited.end()) { // if current queue element is a company and not visited.
  28. visited.insert(curr); // add company to visited (just in case we see it again while iterating)
  29. for (itr = company[curr].begin(); itr != company[curr].end(); ++itr) {
  30. if (visited.find(itr->person_or_company) == visited.end()) { // if not visited, do...
  31. if (person.find(itr->person_or_company) != person.end()) { // if we find the current string in persons.
  32. checker.push(itr->person_or_company); // Queuing.
  33. result.push_back(itr->person_or_company); // push to result array.
  34. visited.insert(itr->person_or_company); // push to visited set.
  35. }
  36. else if (company.find(itr->person_or_company) != company.end()) { // if we find the current string in company.
  37. vector<CompanyStr>::iterator itr2; // iterate over the current company.
  38. for (itr2 = company[itr->person_or_company].begin(); itr2 != company[itr->person_or_company].end(); ++itr2) {
  39. checker.push(itr2->person_or_company); // queue all the persons and company under the current company.
  40. }
  41. }
  42. }
  43. else continue; // if visited, continue
  44. }
  45. }
  46. else if (person.find(curr) != person.end() && visited.find(curr) == visited.end()) { // if current queue element is a person and not visited.
  47. result.push_back(curr); // push to result array.
  48. visited.insert(curr); // push to visited set.
  49. }
  50. }
  51. return result;
  52. }
  53.  
  54. vector<string> all_ownersDFS (string &comp) {
  55. set<string> visited; // Check if i have seen the current person or company.
  56. vector<string> result; // final result.
  57. if (company.find(comp) != company.end()) { // Initial check to see if comp is in company (wrong input).
  58. vector<CompanyStr>::iterator itr; // iterator that runs through in my vector pairs.
  59. for (itr = company[comp].begin(); itr != company[comp].end(); ++itr) {
  60. if (visited.find(itr->person_or_company) == visited.end()) { // if not visited, do...
  61. if (person.find(itr->person_or_company) != person.end()) { // if we find the current string in persons.
  62. result.push_back(itr->person_or_company); // push to result array.
  63. visited.insert(itr->person_or_company); // push to visited set.
  64. }
  65. else if (company.find(itr->person_or_company) != company.end()) { // if we find the current string in company.
  66. all_ownersDFS(itr->person_or_company); // recursive call on company.
  67. }
  68. }
  69. else continue; // if visited, continue
  70. }
  71. }
  72. return result;
  73. }
  74.  
  75. vector<pair<string, int>> all_owners_shares (string &comp) {
  76.  
  77. }
  78. };
  79.  
  80. int main() {
  81. OffShore curr;
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement