Last active
October 11, 2016 20:51
-
-
Save ferreiro/62ee2efd108d2ecc2eba60b033aa889a to your computer and use it in GitHub Desktop.
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 <iostream> | |
using namespace std; | |
const int MAX_DB_SIZE = 10000; | |
struct Car { | |
string name; | |
int lowPrice; | |
int highPrice; | |
}; | |
int main(int argc, const char * argv[]) { | |
int query; | |
int index = 0; | |
int totalCases = 0; | |
int totalQueries = 0; | |
int databaseSize = 0; | |
int dbCounter = 0; | |
int queryHits = 0; | |
Car database[MAX_DB_SIZE]; | |
string name; | |
cin >> totalCases; | |
while (totalCases > 0) { | |
cin >> databaseSize; // Loading database elements | |
dbCounter = 0; | |
for (int i = 0; i < databaseSize; i++) { | |
cin >> database[dbCounter].name; | |
cin >> database[dbCounter].lowPrice; | |
cin >> database[dbCounter].highPrice; | |
dbCounter += 1; | |
} | |
// Making the queries | |
cin >> totalQueries; | |
for (int i = 0; i < totalQueries; i++) { | |
index = 0; | |
queryHits = 0; | |
cin >> query; | |
while (queryHits <= 1 && index < databaseSize) { | |
if (query >= database[index].lowPrice && query <= database[index].highPrice) { | |
queryHits += 1; | |
name = database[index].name; | |
} | |
index += 1; | |
} | |
if (queryHits == 1) cout << name; | |
else cout << "UNDETERMINED"; | |
cout << "\n"; | |
} | |
if (totalCases > 1) cout << "\n"; | |
totalCases -= 1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment