Created
September 20, 2016 05:09
-
-
Save jianminchen/61bdc567cb42b172ffc35f67a6442ff7 to your computer and use it in GitHub Desktop.
HackerRank - Stryker code sprint - cpp solution - less than 15 minutes to write
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
#include <set> | |
#include <map> | |
using namespace std; | |
struct pt { | |
int k; | |
double x, y, z; | |
void read() { | |
cin >> k >> x >> y >> z; | |
} | |
}; | |
bool operator < (const pt &a, const pt &b) { | |
return a.z > b.z; | |
} | |
pt points[100005]; | |
set<int> f; | |
map<int, pt> what; | |
int main() { | |
/* Enter your code here. Read input from STDIN. Print output to STDOUT */ | |
ios::sync_with_stdio(false); | |
int n, b; | |
cin >> n >> b; | |
for (int i = 0; i < n; ++i) | |
points[i].read(); | |
sort(points, points + n); | |
for (int i = 0; i < n; ++i) { | |
what[points[i].k] = points[i]; | |
} | |
for (int i = 0; i < b; ++i) { | |
f.insert(points[i].k); | |
} | |
char c; int id; | |
cout.precision(3); | |
cout << fixed; | |
int ptr = b; | |
while (cin >> c >> id) { | |
if (c == 'f' || c == 'F') { | |
if (f.count(id)) { | |
cout << id << " = (" << what[id].x << "," << what[id].y << "," << what[id].z << ")\n"; | |
} else { | |
cout << "Point doesn't exist in the bucket." << endl; | |
} | |
} else { | |
if (!f.count(id)) { | |
cout << "Point doesn't exist in the bucket." << endl; | |
} else { | |
if (ptr != n) { | |
cout << "Point id " << id << " removed." << endl; | |
f.erase(id); | |
f.insert(points[ptr++].k); | |
} else { | |
cout << "No more points can be deleted." << endl; | |
} | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment