File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,15 @@ std::set<std::string> get_applicants(std::string filename) {
5555 */
5656std::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 */
7179std::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! #### */
You can’t perform that action at this time.
0 commit comments