Language: C++

nclude<bits/stdc++.h>
using namespace std;
main(){
  int n;
  while(cin>>n,n){
    string s[n+1];
    getline(cin,s[0]);
    for(int i=0;i<n;i++)getline(cin,s[i]);
    cin>>s[n];
    int pp=0;
    map<string,int>m;
    for(int i=0;i<n;i++){
      string t;
      for(int j=0;j<s[i].size();j++){
        if(s[i][j]!=' ')t+=s[i][j];
        else{
          if(t[0]==s[n][0]){
            pp=max(pp,(int)t.size());
            m[t]++;
            t="";
          }
          t="";
        }
          if(j==s[i].size()-2){
            if(t[0]==s[n][0]){
            pp=max(pp,(int)t.size());
            m[t]++;
            t="";
          }
        }
      }
    }
    vector<pair<string,int> >v;
    for(map<string,int>::iterator i=m.begin();i!=m.end();i++){
      string t=(*i).first,tt;
      int r=(*i).second,o=(int)t.size()-pp;
      while(o<=0)t=t+'~',o++;
      v.push_back(make_pair(t,-r));
    }
    sort(v.begin(),v.end(),greater<pair<string,int> >());

    //stable_sort(v1.begin(),v1.end());
    if(v.size()==0)cout<<"NA";
    else for(int i=v.size()-1,k=0;i>=0;i--,k++){
      if(k==5)break;
      if(i!=v.size()-1)cout<<' ';
      for(int j=0;j<v[i].first.size();j++)
        if(v[i].first[j]!='~')cout<<v[i].first[j];
    }
    cout<<endl;
  }
}

Compiler output:
a.cc:1:1: error: 'nclude' does not name a type
    1 | nclude<bits/stdc++.h>
      | ^~~~~~
a.cc:3:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    3 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:5:9: error: 'cin' was not declared in this scope
    5 |   while(cin>>n,n){
      |         ^~~
a.cc:6:5: error: 'string' was not declared in this scope
    6 |     string s[n+1];
      |     ^~~~~~
a.cc:7:17: error: 's' was not declared in this scope
    7 |     getline(cin,s[0]);
      |                 ^
a.cc:7:5: error: 'getline' was not declared in this scope
    7 |     getline(cin,s[0]);
      |     ^~~~~~~
a.cc:11:5: error: 'map' was not declared in this scope
   11 |     map<string,int>m;
      |     ^~~
a.cc:11:16: error: expected primary-expression before 'int'
   11 |     map<string,int>m;
      |                ^~~
a.cc:13:13: error: expected ';' before 't'
   13 |       string t;
      |             ^~
      |             ;
a.cc:15:25: error: 't' was not declared in this scope
   15 |         if(s[i][j]!=' ')t+=s[i][j];
      |                         ^
a.cc:17:14: error: 't' was not declared in this scope
   17 |           if(t[0]==s[n][0]){
      |              ^
a.cc:18:16: error: 'max' was not declared in this scope
   18 |             pp=max(pp,(int)t.size());
      |                ^~~
a.cc:19:13: error: 'm' was not declared in this scope
   19 |             m[t]++;
      |             ^
a.cc:22:11: error: 't' was not declared in this scope
   22 |           t="";
      |           ^
a.cc:25:16: error: 't' was not declared in this scope
   25 |             if(t[0]==s[n][0]){
      |                ^
a.cc:26:16: error: 'max' was not declared in this scope
   26 |             pp=max(pp,(int)t.size());
      |                ^~~
a.cc:27:13: error: 'm' was not declared in this scope
   27 |             m[t]++;
      |             ^
a.cc:33:5: error: 'vector' was not declared in this scope
   33 |     vector<pair<string,int> >v;
      |     ^~~~~~
a.cc:33:12: error: 'pair' was not declared in this scope
   33 |     vector<pair<string,int> >v;
      |            ^~~~
a.cc:33:24: error: expected primary-expression before 'int'
   33 |     vector<pair<string,int> >v;
      |                        ^~~
a.cc:34:20: error: expected primary-expression before 'int'
   34 |     for(map<string,int>::iterator i=m.begin();i!=m.end();i++){
      |                    ^~~
a.cc:34:47: error: 'i' was not declared in this scope
   34 |     for(map<string,int>::iterator i=m.begin();i!=m.end();i++){
      |                                               ^
a.cc:34:50: error: 'm' was not declared in this scope
   34 |     for(map<string,int>::iterator i=m.begin();i!=m.end();i++){
      |                                                  ^
a.cc:35:13: error: expected ';' before 't'
   35 |       string t=(*i).first,tt;
      |             ^~
      |             ;
a.cc:37:13: error: 'o' was not declared in this scope
   37 |       while(o<=0)t=t+'~',o++;
      |             ^
a.cc:37:18: error: 't' was not declared in this scope
   37 |       while(o<=0)t=t+'~',o++;
      |                  ^
a.cc:38:7: error: 'v' was not declared in this scope
   38 |       v.push_back(make_pair(t,-r));
      |       ^
a.cc:38:29: error: 't' was not declared in this scope
   38 |       v.push_back(make_pair(t,-r));
      |                             ^
a.cc:38:19: error: 'make_pair' was not declared in this scope
   38 |       v.push_back(make_pair(t,-r));
      |                   ^~~~~~~~~
a.cc:40:10: error: 'v' was not declared in this scope
   40 |     sort(v.begin(),v.end(),greater<pair<string,int> >());
      |          ^
a.cc:40:28: error: 'greater' was not declared in this scope
   40 |     sort(v.begin(),v.end(),greater<pair<string,int> >());
      |                            ^~~~~~~
a.cc:40:48: error: expected primary-expression before 'int'
   40 |     sort(v.begin(),v.end(),greater<pair<string,int> >());
      |                                                ^~~
a.cc:40:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   40 |     sort(v.begin(),v.end(),greater<pair<string,int> >());
      |     ^~~~
      |     short
a.cc:43:20: error: 'cout' was not declared in this scope
   43 |     if(v.size()==0)cout<<"NA";
      |                    ^~~~
a.cc:44:44: error: 'k' was not declared in this scope
   44 |     else for(int i=v.size()-1,k=0;i>=0;i--,k++){
      |                                            ^
a.cc:46:24: error: 'cout' was not declared in this scope
   46 |       if(i!=v.size()-1)cout<<' ';
      |                        ^~~~
a.cc:48:31: error: 'cout' was not declared in this scope
   48 |         if(v[i].first[j]!='~')cout<<v[i].first[j];
      |                               ^~~~
a.cc:50:5: error: 'cout' was not declared in this scope
   50 |     cout<<endl;
      |     ^~~~
a.cc:50:11: error: 'endl' was not declared in this scope
   50 |     cout<<endl;
      |           ^~~~