Skip to content
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
43 changes: 43 additions & 0 deletions week-8/C++/Branch-Hezekiah-Problem2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <iostream>
#include <bits/stdc++.h>

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<T> 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;
}
Binary file added week-8/C++/main
Binary file not shown.
67 changes: 67 additions & 0 deletions week-8/C++/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

#include <iostream>
#include <algorithm> // std::sort
#include <vector>
#include <bits/stdc++.h>

using namespace std;

// Function Prototypes
// Populate vectors with data from provided input
void preload_vectors(vector<int> * s, vector<int> * q);
// Binary search implementation
void binary_search(int target);

// Main function containing solution
int main ()
{
// Container for number of stones + queries
vector<int> stones;
vector<int> queries;
preload_vectors(&stones, &queries);
// Start checking the queries
queue<int> 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<int> * stones,
vector<int> * 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<int> list
// Purpose: Rapidly find an element in a sorted list
// Runtime: O(logn)
void binary_search(int target, vector<int> * list)
{
cout << "LOADING BINARY SEARCH..." << endl;
}