diff --git a/.gitignore b/.gitignore index 519028e..5cc964d 100644 --- a/.gitignore +++ b/.gitignore @@ -40,12 +40,5 @@ Thumbs.db *.exe *.war -# Large media files -*.mp4 -*.tiff -*.avi -*.flv -*.mov -*.wmv -*.jjj + diff --git a/anish_bhat_k.mp4 b/anish_bhat_k.mp4 new file mode 100644 index 0000000..5a50b92 Binary files /dev/null and b/anish_bhat_k.mp4 differ diff --git a/code.cpp b/code.cpp new file mode 100644 index 0000000..9df02dc --- /dev/null +++ b/code.cpp @@ -0,0 +1,71 @@ +#include +using namespace std; + +int getNumber(string temp) +{ + string prev; + stringstream ss(temp); + while (ss >> temp) + prev = temp; + return stoi(prev); +} + +string getName(string temp){ + string res; + stringstream ss(temp); + while (ss >> temp){ + if(res.empty()) + res = temp; + else + res = res +" "+ temp; + if(temp.back()==':'){ + res.pop_back(); + return res; + } + } + return res; +} + + +int main(){ + ios_base::sync_with_stdio(false); + cin.tie(0); + cout.tie(0); + + int numberOfEmployees=0; + string temp, prev; + getline(cin, temp); + vector prices; + unordered_map gifts; + numberOfEmployees = getNumber(temp); + getline(cin, temp); + getline(cin, temp); + getline(cin, temp); + while (getline(cin, temp)){ + if (temp.empty()) + break; + string name = getName(temp); + int price = getNumber(temp); + gifts[price] = name; + prices.push_back(price); + } + sort(prices.begin(), prices.end()); + int minDiff = INT_MAX; + int start = 0; + int n = prices.size(); + for (int i = n - 1; i - numberOfEmployees>=0; i--){ + int curDiff = prices[i]-prices[i-numberOfEmployees]; + if(curDiff < minDiff){ + minDiff = curDiff; + start = i - numberOfEmployees+1; + } + } + + cout << "The goodies selected for distribution are:\n\n"; + for (int i = start; i < start + numberOfEmployees; i++) + cout + << gifts[prices[i]] << ": " << prices[i] << '\n'; + + cout << "And the difference between the chosen goodie with highest price and the lowest price is " << prices[start + numberOfEmployees-1] - prices[start] << '\n'; + return 0; +} \ No newline at end of file diff --git a/input.txt b/input.txt new file mode 100644 index 0000000..dc548cb --- /dev/null +++ b/input.txt @@ -0,0 +1,49 @@ +Number of employees: 3 +Goodies and Prices: + +Fitbit Plus: 7980 +IPods: 22349 +MI Band: 999 +Cult Pass: 2799 +Macbook Pro: 229900 +Digital Camera: 11101 +Alexa: 9999 +Sandwich Toaster: 2195 +Microwave Oven: 9800 +Scale: 4999 + +################################## + + +Number of employees: 4 + +Goodies and Prices: + +Fitbit Plus: 7980 +IPods: 22349 +MI Band: 999 +Cult Pass: 2799 +Macbook Pro: 229900 +Digital Camera: 11101 +Alexa: 9999 +Sandwich Toaster: 2195 +Microwave Oven: 9800 +Scale: 4999 + + +###################################### + +Number of employees: 5 + +Goodies and Prices: + +Fitbit Plus: 7980 +IPods: 22349 +MI Band: 999 +Cult Pass: 2799 +Macbook Pro: 229900 +Digital Camera: 11101 +Alexa: 9999 +Sandwich Toaster: 2195 +Microwave Oven: 9800 +Scale: 4999 \ No newline at end of file