Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct CountryPoints
  5. {
  6. string Name;
  7. int Points;
  8. };
  9. struct Country
  10. {
  11. string Name;
  12. string Song;
  13. string Participant;
  14. vector<CountryPoints> GivingPoints;
  15. int Points;
  16. };
  17.  
  18. int FindIndexOfSymbol(string input, char symbol, int start)
  19. {
  20. int indexOfSymbol = -1;
  21. for(int index = start; index < input.size(); index++)
  22. {
  23. if (input[index] == symbol)
  24. {
  25. indexOfSymbol = index;
  26. break;
  27. }
  28. }
  29. return indexOfSymbol;
  30. }
  31. string Substring(string input, int start, int stop)
  32. {
  33. string temp = "";
  34. for(int index = start; index <= stop; index++)
  35. {
  36. temp += input[index];
  37. }
  38. return temp;
  39. }
  40. int ParseInt(string input)
  41. {
  42. int result = 0;
  43. if (input == "1")
  44. {
  45. result = 1;
  46. }
  47. else if (input == "2")
  48. {
  49. result = 2;
  50. }
  51. else if (input == "3")
  52. {
  53. result = 3;
  54. }
  55. else if (input == "4")
  56. {
  57. result = 4;
  58. }
  59. else if (input == "5")
  60. {
  61. result = 5;
  62. }
  63. else if (input == "6")
  64. {
  65. result = 6;
  66. }
  67. else if (input == "7")
  68. {
  69. result = 7;
  70. }
  71. else if (input == "8")
  72. {
  73. result = 8;
  74. }
  75. else if (input == "10")
  76. {
  77. result = 10;
  78. }
  79. else if (input == "11")
  80. {
  81. result = 11;
  82. }
  83. else if (input == "12")
  84. {
  85. result = 12;
  86. }
  87. return result;
  88.  
  89. }
  90. vector<string> SplitByComma(string input)
  91. {
  92. vector <string> tokens;
  93. input += ",";
  94. int index = FindIndexOfSymbol(input, ',', 0);
  95. int currStart = 0;
  96.  
  97. while(index != -1)
  98. {
  99. string curr = Substring(input, currStart, index - 1);
  100. input = Substring(input, index + 2, input.size() - 1);
  101. index = FindIndexOfSymbol(input, ',', 0);
  102. tokens.push_back(curr);
  103. }
  104. return tokens;
  105. }
  106. CountryPoints ReturnCountryPoints(string input)
  107. {
  108. int spaceIndex = FindIndexOfSymbol(input, ' ', 0);
  109. int currStart = 0;
  110. CountryPoints curr;
  111.  
  112. curr.Name = Substring(input, 0, spaceIndex - 1);
  113. string pointsInString = Substring(input, spaceIndex + 3, input.size() - 1);
  114. curr.Points = ParseInt(pointsInString);
  115.  
  116. return curr;
  117. }
  118. void ReadCountries(vector<Country> &countries, int num)
  119. {
  120. for(int counter = 0; counter < num; counter++)
  121. {
  122. cin.ignore();
  123. Country currentCountry;
  124. cout<<"Enter Country: ";
  125. cin>>currentCountry.Name;
  126. cin.ignore();
  127. cout<<"Enter Song: ";
  128. getline(cin, currentCountry.Song);
  129. cout<<"Enter Participant Fullname: ";
  130. getline(cin, currentCountry.Participant);
  131. string givingPointsInputString;
  132. cout<<"Enter GivingPoints: ";
  133. getline(cin, givingPointsInputString);
  134. vector<string> givingPointsInput = SplitByComma(givingPointsInputString);
  135. for(int index = 0; index < givingPointsInput.size(); index++)
  136. {
  137. CountryPoints points = ReturnCountryPoints(givingPointsInput[index]);
  138. currentCountry.GivingPoints.push_back(points);
  139. }
  140.  
  141. currentCountry.Points = 0;
  142. countries.push_back(currentCountry);
  143. }
  144. }
  145. void CalculatePoints(vector<Country> countries)
  146. {
  147. for(int index = 0; index < countries.size(); index++)
  148. {
  149. Country currentCountry = countries[index];
  150. for(int innerIndex = 0; innerIndex < countries.size(); innerIndex++)
  151. {
  152. Country otherCountry = countries[innerIndex];
  153. if (otherCountry.Name != currentCountry.Name)
  154. {
  155. //loop through points to give
  156. for(int i = 0; i < otherCountry.GivingPoints.size(); i++)
  157. {
  158. CountryPoints currentGivingPoints = otherCountry.GivingPoints[i];
  159. if (currentGivingPoints.Name == currentCountry.Name)
  160. {
  161. countries[index].Points += currentGivingPoints.Points;
  162. cout<<5<<endl;
  163. }
  164. }
  165. }
  166. }
  167. }
  168. }
  169. void Print(Country current)
  170. {
  171. cout<<"Name: "<<current.Name<<" -> "<<current.Points<<endl;
  172. }
  173. void PrintAllCountries(vector<Country> countries)
  174. {
  175. for(int index = 0; index < countries.size(); index++)
  176. {
  177. Print(countries[index]);
  178. }
  179. }
  180. void Sort(vector<CountryPoints> &arr)
  181. {
  182. for (int i = 0; i < arr.size(); i++)
  183. {
  184. for (int j = 0; j < arr.size()-i-1; j++)
  185. {
  186. if (arr[j].Points > arr[j+1].Points)
  187. {
  188. swap(arr[j], arr[j+1]);
  189. }
  190.  
  191. }
  192. }
  193. }
  194. int main()
  195. {
  196. int countriesCount;
  197. cout<<"Enter countries count: ";
  198. cin>>countriesCount;
  199.  
  200. vector<Country> countries;
  201. ReadCountries(countries, countriesCount);
  202. CalculatePoints(countries);
  203. PrintAllCountries(countries);
  204.  
  205. return 0;
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement