Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct CountryPoints
- {
- string Name;
- int Points;
- };
- struct Country
- {
- string Name;
- string Song;
- string Participant;
- vector<CountryPoints> GivingPoints;
- int Points;
- };
- int FindIndexOfSymbol(string input, char symbol, int start)
- {
- int indexOfSymbol = -1;
- for(int index = start; index < input.size(); index++)
- {
- if (input[index] == symbol)
- {
- indexOfSymbol = index;
- break;
- }
- }
- return indexOfSymbol;
- }
- string Substring(string input, int start, int stop)
- {
- string temp = "";
- for(int index = start; index <= stop; index++)
- {
- temp += input[index];
- }
- return temp;
- }
- int ParseInt(string input)
- {
- int result = 0;
- if (input == "1")
- {
- result = 1;
- }
- else if (input == "2")
- {
- result = 2;
- }
- else if (input == "3")
- {
- result = 3;
- }
- else if (input == "4")
- {
- result = 4;
- }
- else if (input == "5")
- {
- result = 5;
- }
- else if (input == "6")
- {
- result = 6;
- }
- else if (input == "7")
- {
- result = 7;
- }
- else if (input == "8")
- {
- result = 8;
- }
- else if (input == "10")
- {
- result = 10;
- }
- else if (input == "11")
- {
- result = 11;
- }
- else if (input == "12")
- {
- result = 12;
- }
- return result;
- }
- vector<string> SplitByComma(string input)
- {
- vector <string> tokens;
- input += ",";
- int index = FindIndexOfSymbol(input, ',', 0);
- int currStart = 0;
- while(index != -1)
- {
- string curr = Substring(input, currStart, index - 1);
- input = Substring(input, index + 2, input.size() - 1);
- index = FindIndexOfSymbol(input, ',', 0);
- tokens.push_back(curr);
- }
- return tokens;
- }
- CountryPoints ReturnCountryPoints(string input)
- {
- int spaceIndex = FindIndexOfSymbol(input, ' ', 0);
- int currStart = 0;
- CountryPoints curr;
- curr.Name = Substring(input, 0, spaceIndex - 1);
- string pointsInString = Substring(input, spaceIndex + 3, input.size() - 1);
- curr.Points = ParseInt(pointsInString);
- return curr;
- }
- void ReadCountries(vector<Country> &countries, int num)
- {
- for(int counter = 0; counter < num; counter++)
- {
- cin.ignore();
- Country currentCountry;
- cout<<"Enter Country: ";
- cin>>currentCountry.Name;
- cin.ignore();
- cout<<"Enter Song: ";
- getline(cin, currentCountry.Song);
- cout<<"Enter Participant Fullname: ";
- getline(cin, currentCountry.Participant);
- string givingPointsInputString;
- cout<<"Enter GivingPoints: ";
- getline(cin, givingPointsInputString);
- vector<string> givingPointsInput = SplitByComma(givingPointsInputString);
- for(int index = 0; index < givingPointsInput.size(); index++)
- {
- CountryPoints points = ReturnCountryPoints(givingPointsInput[index]);
- currentCountry.GivingPoints.push_back(points);
- }
- currentCountry.Points = 0;
- countries.push_back(currentCountry);
- }
- }
- void CalculatePoints(vector<Country> countries)
- {
- for(int index = 0; index < countries.size(); index++)
- {
- Country currentCountry = countries[index];
- for(int innerIndex = 0; innerIndex < countries.size(); innerIndex++)
- {
- Country otherCountry = countries[innerIndex];
- if (otherCountry.Name != currentCountry.Name)
- {
- //loop through points to give
- for(int i = 0; i < otherCountry.GivingPoints.size(); i++)
- {
- CountryPoints currentGivingPoints = otherCountry.GivingPoints[i];
- if (currentGivingPoints.Name == currentCountry.Name)
- {
- countries[index].Points += currentGivingPoints.Points;
- cout<<5<<endl;
- }
- }
- }
- }
- }
- }
- void Print(Country current)
- {
- cout<<"Name: "<<current.Name<<" -> "<<current.Points<<endl;
- }
- void PrintAllCountries(vector<Country> countries)
- {
- for(int index = 0; index < countries.size(); index++)
- {
- Print(countries[index]);
- }
- }
- void Sort(vector<CountryPoints> &arr)
- {
- for (int i = 0; i < arr.size(); i++)
- {
- for (int j = 0; j < arr.size()-i-1; j++)
- {
- if (arr[j].Points > arr[j+1].Points)
- {
- swap(arr[j], arr[j+1]);
- }
- }
- }
- }
- int main()
- {
- int countriesCount;
- cout<<"Enter countries count: ";
- cin>>countriesCount;
- vector<Country> countries;
- ReadCountries(countries, countriesCount);
- CalculatePoints(countries);
- PrintAllCountries(countries);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement