Language: C++

#include<iostream>
#include<algorithm>
#include<iterator>
#include<string>
#include<sstream>
#include<vector>
#include<map>

using namespace std;

struct pard {
	bool operator()(const pair<string, int>& _Left, const pair<string, int>& _Right) {
		return _Left.second != _Right.second ? _Left.second > _Right.second : _Left.first < _Right.first;
	}
};

int main() {
	int n;
	string line;
	char initial;

	while(cin >> n && n) {
		cin.ignore(numeric_limits<streamsize>::max(), '\n');
		map<string, int> date_m;
		while(n--) {	
			getline(cin, line);
			istringstream iss(line);
			for(istream_iterator<string> ite = istream_iterator<string>(iss); ite != istream_iterator<string>(); ++ite) {
				++date_m.insert(make_pair(*ite, 0)).first->second;
			}
		}
		
		cin >> initial;
		vector< pair<string, int> > date_v(5);
		vector< pair<string, int> >::iterator first = date_v.begin(), last = partial_sort_copy(
			date_m.lower_bound(string(1, initial)), date_m.lower_bound(string(1, initial + 1)),
			date_v.begin(), date_v.end(), pard()
			);

		cout << (first != last ? first++->first : "NA");
		while(first != last) cout << ' ' << first++->first;
		cout << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:28: error: 'numeric_limits' was not declared in this scope
   23 |                 cin.ignore(numeric_limits<streamsize>::max(), '\n');
      |                            ^~~~~~~~~~~~~~
a.cc:23:53: error: expected primary-expression before '>' token
   23 |                 cin.ignore(numeric_limits<streamsize>::max(), '\n');
      |                                                     ^
a.cc:23:59: error: no matching function for call to 'max()'
   23 |                 cin.ignore(numeric_limits<streamsize>::max(), '\n');
      |                                                      ~~~~~^~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 0 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   candidate expects 2 arguments, 0 provided