Skip to content

Commit 52814ae

Browse files
Zane LiaoZane Liao
authored andcommitted
Look others Solution, Finish
1 parent fce908f commit 52814ae

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

assign2/main.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,15 @@ std::set<std::string> get_applicants(std::string filename) {
5555
*/
5656
std::queue<const std::string*> find_matches(std::string name, std::set<std::string>& students) {
5757
// STUDENT TODO: Implement this function.
58+
std::queue<const std::string*> result;
5859

60+
for (const auto& student : students) {
61+
if (student == name) {
62+
result.push(&student);
63+
}
64+
}
65+
66+
return result;
5967
}
6068

6169
/**
@@ -70,6 +78,24 @@ std::queue<const std::string*> find_matches(std::string name, std::set<std::stri
7078
*/
7179
std::string get_match(std::queue<const std::string*>& matches) {
7280
// STUDENT TODO: Implement this function.
81+
// Others Solution
82+
if (matches.empty()) {
83+
return "NO MATCHES FOUND.";
84+
}
85+
86+
const std::string* match = nullptr;
87+
size_t min_length = 0;
88+
while (!matches.empty()) {
89+
const std::string* current_match = matches.front();
90+
91+
if (min_length < current_match->length()) {
92+
min_length = current_match->length();
93+
match = current_match;
94+
}
95+
matches.pop();
96+
}
97+
98+
return match ? *match : "NO MATCHES FOUND.";
7399
}
74100

75101
/* #### Please don't remove this line! #### */

0 commit comments

Comments
 (0)