Language: C++

#include<bits/stdc++.h>
using namespace std;
string S;
int main(){
	int n;
	while(true){
		cin>>n;vector<string>vec;
		vector<pair<int,string> >w;
		if(n==0){break;}
		for(int i=0;i<n;i++){
			S="";
			while(S==""){
				getline(cin,S);
			}
			S+=" ";string T;
			for(int i=0;i<S.size();i++){
				if(S[i]==' '){vec.push_back(T);T="";}
				else{T+=S[i];}
			}
		}
		char c;cin>>c;sort(vec.begin(),vec.end());
		if(vec[0][0]==c)w.push_back(make_pair(-1,vec[0]));
		for(int i=1;i<vec.size();i++){
			if(vec[i][0]==c){
				if(vec[i]==vec[i-1]){vec[vec.size()-1].first--;}
				else{vec.push_back(make_pair(-1,vec[i]));}
			}
		}
		sort(w.begin(),w.end());
		if(w.size()==0){cout<<"NA";}
		else{
			for(int i=0;i<w.size();i++){
				if(i>=5){break;}
				if(i){cout<<' ';}
				cout<<w[i].second;
			}
		}
		cout<<endl;
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:72: error: '__gnu_cxx::__alloc_traits<std::allocator<std::__cxx11::basic_string<char> >, std::__cxx11::basic_string<char> >::value_type' {aka 'class std::__cxx11::basic_string<char>'} has no member named 'first'
   25 |                                 if(vec[i]==vec[i-1]){vec[vec.size()-1].first--;}
      |                                                                        ^~~~~
a.cc:26:51: error: no matching function for call to 'std::vector<std::__cxx11::basic_string<char> >::push_back(std::pair<int, std::__cxx11::basic_string<char> >)'
   26 |                                 else{vec.push_back(make_pair(-1,vec[i]));}
      |                                      ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::__cxx11::basic_string<char>; _Alloc = std::allocator<std::__cxx11::basic_string<char> >; value_type = std::__cxx11::basic_string<char>]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from 'std::pair<int, std::__cxx11::basic_string<char> >' to 'const std::vector<std::__cxx11::basic_string<char> >::value_type&' {aka 'const std::__cxx11::basic_string<char>&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::__cxx11::basic_string<char>; _Alloc = std::allocator<std::__cxx11::basic_string<char> >; value_type = std::__cxx11::basic_string<char>]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from 'std::pair<int, std::__cxx11::basic_string<char> >' to 'std::vector<std::__cxx11::basic_string<char> >::value_type&&' {aka 'std::__cxx11::basic_string<char>&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~