diff --git a/week-8/C++/Branch-Hezekiah-Problem2.cpp b/week-8/C++/Branch-Hezekiah-Problem2.cpp new file mode 100644 index 0000000..98930bc --- /dev/null +++ b/week-8/C++/Branch-Hezekiah-Problem2.cpp @@ -0,0 +1,43 @@ +#include +#include + +using namespace std; + +struct T { + long data; + long count; +}; + +// Main function containing solution to problem 2 +int main () +{ + // Get total size of vector needed + long size; + cin >> size; + vector values(size + 1); + // Get input values + long input; + while (size > 0) { + cin >> input; + if (values[input].count > 0) { + values[input].count += 1; + } else { + T object; + object.data = input; + object.count = 1; + values[input] = object; + } + size -= 1; + } + // Get K from input space + long k; cin >> k; + // Check values + long min = 100001; + for (auto object : values) { + if (object.count == k && object.data < min) { + min = object.data; + } + } + cout << min; + return 0; +} \ No newline at end of file diff --git a/week-8/C++/main b/week-8/C++/main new file mode 100644 index 0000000..36aa7f2 Binary files /dev/null and b/week-8/C++/main differ diff --git a/week-8/C++/main.cpp b/week-8/C++/main.cpp index e69de29..34ffdd1 100644 --- a/week-8/C++/main.cpp +++ b/week-8/C++/main.cpp @@ -0,0 +1,67 @@ + +#include +#include // std::sort +#include +#include + +using namespace std; + +// Function Prototypes +// Populate vectors with data from provided input +void preload_vectors(vector * s, vector * q); +// Binary search implementation +void binary_search(int target); + +// Main function containing solution +int main () +{ + // Container for number of stones + queries + vector stones; + vector queries; + preload_vectors(&stones, &queries); + // Start checking the queries + queue found; + for (auto stone : stones) { + cout << stone << " "; + } + return 0; +} + +// ---------------------------------------------------------------- + +// Preload Vectors +// Parameters: Int vectors of stones and queries +// Purpose: Populate vectors with user input of stone info +// Runtime: O(length of stones + length of queries) +void preload_vectors(vector * stones, + vector * queries) +{ + // Get input of days and queries + int days; + int query_count; + cin >> days; + cin >> query_count; + // Input values as integers + int t; int q; + while (days > 0) { + cin >> t; + stones -> push_back(t); + days -= 1; + } + while (query_count > 0) { + cin >> q; + queries -> push_back(q); + query_count -= 1; + } + // Sort the vector of stones O(nlogn) + sort(stones -> begin(), stones -> end()); +} + +// Binary Search +// Parameters: int (to search for), vector list +// Purpose: Rapidly find an element in a sorted list +// Runtime: O(logn) +void binary_search(int target, vector * list) +{ + cout << "LOADING BINARY SEARCH..." << endl; +}