Skip to content

Anish Bhat K submission #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,5 @@ Thumbs.db
*.exe
*.war

# Large media files
*.mp4
*.tiff
*.avi
*.flv
*.mov
*.wmv
*.jjj


Binary file added anish_bhat_k.mp4
Binary file not shown.
71 changes: 71 additions & 0 deletions code.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include<bits/stdc++.h>
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<int> prices;
unordered_map<int, string> 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;
}
49 changes: 49 additions & 0 deletions input.txt
Original file line number Diff line number Diff line change
@@ -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