Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.09 KB | None | 0 0
  1. /*******************************************************************************************************
  2. Name: Emmanuel Obi
  3. Description:
  4. Pokemon Go Go is a program that enables users to access pokestop locations close to the user's current
  5. location, and also pokemons that could be found at each pokestop. The unique quality of this program is it's capability
  6. of computing the shortest route a user could take to catch all pokemons, and return to the starting location.
  7. Firstly, the program requires an input. The first input is a single integer n , which represents the number of pokestation to be
  8. considered such that 0 < n < 11. The next set of input(s) will be two integers (x, y) separated by a space, which represents
  9. the location of the pokestation(s) on a map represented with a 2D vector .e.g vector<vector<int> ;
  10. followed by a single space and the name of the pokemon (x), such that x is a string.
  11. Secondly, the program has an output at the end of it's computation, which is a single line of integers(each integers are
  12. spaced out). This integers represents the order of pokestop to be visited in an optimized way, such that the distance
  13. traveled is the shortest/optimize distance route. The last integer in the line represents the total distance traveled in
  14. blocks. If there are two pokestations with the same total distance, the numerically first pokestation is outputed.
  15. *********************************************************************************************************/
  16. #include <iostream>
  17. #include <vector>
  18. #include <algorithm>
  19. #include <string>
  20. #include <queue>
  21. using namespace std;
  22.  
  23. struct Pokemon
  24. {
  25. Pokemon(string name, int order, int x = 0, int y = 0)
  26. {
  27. pokemonName = name;
  28. postionOrder = order;
  29. xCordinate = x;
  30. yCordinate = y;
  31. }
  32. int postionOrder;
  33. string pokemonName;
  34. int xCordinate;
  35. int yCordinate;
  36. };
  37.  
  38. class PokemonGoGo
  39. {
  40. public:
  41. PokemonGoGo()
  42. {
  43. //Matrix Vector //Initialize Vector as Empty Map
  44. }
  45. void addPokemon(Pokemon* pokemon)
  46. {
  47. unvisitedPokemon.push_back(*pokemon); //Get item of the pointer parameter
  48. }
  49. void extractUniquePokemon(string nameOfPokemon)
  50. {
  51. if (!pokemonReptitionCheck(nameOfPokemon))
  52. uniquePokemonNames.push_back(nameOfPokemon);
  53. }
  54. void pokemonGrouping()
  55. {
  56. vector<Pokemon> temp;
  57. for (int i = 0; i < uniquePokemonNames.size(); i++)
  58. {
  59. temp.swap(vector<Pokemon>()); //Clear Temp
  60. for (int j = 0; j < unvisitedPokemon.size(); j++)
  61. {
  62. if (uniquePokemonNames[i] == unvisitedPokemon[j].pokemonName)
  63. temp.push_back(unvisitedPokemon[j]);
  64. }
  65. groupedPokemon.push_back(temp);
  66. }
  67. }
  68. void pokemonGroupingOrder()
  69. {
  70. vector<int> temp;
  71. for (int i = 0; i < uniquePokemonNames.size(); i++)
  72. {
  73. temp.swap(vector<int>()); //Clear Temp
  74. for (int j = 0; j < unvisitedPokemon.size(); j++)
  75. {
  76. if (uniquePokemonNames[i] == unvisitedPokemon[j].pokemonName)
  77. temp.push_back(unvisitedPokemon[j].postionOrder);
  78. }
  79. groupedPokemonOrder.push_back(temp);
  80. }
  81. }
  82. bool pokemonReptitionCheck(string pokemon)
  83. {
  84. bool repetitonFound = false;
  85. for (int i = 0; i < uniquePokemonNames.size(); i++)
  86. {
  87. if (uniquePokemonNames[i] == pokemon)
  88. repetitonFound = true;
  89. }
  90. return repetitonFound;
  91. }
  92. /*void combinations(vector<vector<int>> groupOfPokemon, int index, vector<int> set)
  93. {
  94. vector<int> row; vector<int> temp;
  95. if (index == groupOfPokemon.size())
  96. {
  97. visitedPokemon.push_back(set);
  98. }
  99. else
  100. {
  101. row = groupOfPokemon[index];
  102. for (int j = 0; j < row.size(); j++)
  103. {
  104. temp.swap(set);
  105. temp.push_back(row[j]);
  106. combinations(groupOfPokemon, index + 1, temp);
  107. }
  108. }
  109. }*/
  110.  
  111. /*bool oneFromEach(vector<int> generatedSet)
  112. {
  113. for (int i = 0; i < groupedPokemon.size(); i++)
  114. {
  115. if (generatedSet[i] == groupedPokemon[i].size() - 1)
  116. generatedSet[i] = groupedPokemon[i][i].postionOrder;
  117. else
  118. {
  119. generatedSet[i] = groupedPokemon[i][i+1].postionOrder;
  120. return true;
  121. }
  122. }
  123. return false;
  124. }*/
  125. /*void printUniquePokemons()
  126. {
  127. vector <int> set;
  128. do
  129. {
  130. for (int i = 0; i < groupedPokemon.size(); i++)
  131. {
  132. for (int j = 0; j < groupedPokemon[i].size(); j++)
  133. {
  134. set.push_back(groupedPokemon[i][j].postionOrder);
  135. cout << groupedPokemon[i][j].postionOrder;
  136. }
  137. }
  138. } while (oneFromEach(set));
  139. }*/
  140. void print()
  141. {
  142. //combinations(groupedPokemonOrder, 0, vector<int>());
  143.  
  144. /*for (int i = 0; i < visitedPokemon.size(); i++)
  145. {
  146. for (int j = 0; j < visitedPokemon[i].size(); j++)
  147. {
  148. cout << visitedPokemon[i][j];
  149. }
  150. }*/
  151.  
  152. }
  153. private:
  154.  
  155. vector<string> uniquePokemonNames;
  156. vector<vector<Pokemon>> groupedPokemon;
  157. vector<vector<int>> visitedPokemon;
  158. vector<vector<int>> groupedPokemonOrder;
  159. vector<Pokemon> unvisitedPokemon;
  160. /*string pokemons;
  161. int locationID;*/
  162. };
  163. ostream& operator<<(ostream& out, const vector<int>& vec)
  164. {
  165. for (auto x : vec)
  166. out << x;
  167. return out;
  168. }
  169.  
  170. int main()
  171. {
  172. PokemonGoGo pokemonGame; //Container
  173. int numberOfPokestations;
  174. int xLoc; int yLoc; string pokemonName;
  175.  
  176. cin >> numberOfPokestations;
  177.  
  178. for (int i = 1; i <= numberOfPokestations; i++)
  179. {
  180. cin >> xLoc >> yLoc >> pokemonName;
  181.  
  182. pokemonGame.addPokemon(new Pokemon(pokemonName, i, xLoc, yLoc));
  183. pokemonGame.extractUniquePokemon(pokemonName);
  184. }
  185. pokemonGame.pokemonGroupingOrder();
  186. pokemonGame.print();
  187.  
  188. //pokemonGame.printUniquePokemons();
  189.  
  190.  
  191. return 0;
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement