Language: C++

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <functional>
#include <queue>
#include <string>
#include <map>
#include <vector>

using namespace std;

bool cmp(pair<string, int> a, pair<string, int> b) {
  return a.second > b.second || (a.second == b.second && a.first < b.first);
}

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (!n) return 0;
    string s, l;
    getline(cin, l);
    for (int i = 0; i < n; i++) {
      getline(cin, l);
      s += l;
      s += ' ';
    }
    char k;
    cin >> k;
    int c = 0;
    char w[21];
    map<string, int> freq;
    for (int i = 0; i < s.length(); i++)
      if (s[i] == ' ' && c) {
        w[c] = '\0';
        if (w[0] == k) freq[w]++;
        c = 0;
      } else
        w[c++] = s[i];
    vector<pair<string, int> > v;
    for (map<string, int>::iterator p = freq.begin(); p != freq.end(); ++p)
      v.push_back(*p);
    if (v.empty())
      cout << "NA" << endl;
    else {
      sort(v.begin(), v.end(), cmp);
      for (int i = 0; i < min(v.size(), 5); i++)
        cout << v[i].first << ' ';
      cout << endl;
    }
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:49:30: error: no matching function for call to 'min(std::vector<std::pair<std::__cxx11::basic_string<char>, int> >::size_type, int)'
   49 |       for (int i = 0; i < min(v.size(), 5); i++)
      |                           ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:49:30: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'int')
   49 |       for (int i = 0; i < min(v.size(), 5); i++)
      |                           ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:49:30: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
   49 |       for (int i = 0; i < min(v.size(), 5); i++)
      |                           ~~~^~~~~~~~~~~~~