2 solutions

  • 3
    @ 2026-4-26 10:45:25
    #include<bits/stdc++.h>
    using namespace std;
    const int N=30;
    vector<string> g[N];
    int cnt[N];
    int now[N];
    int main()
    {
        int n,m;cin>>n>>m;
        for(int i=1;i<=n;i++)
        {
            string s;cin>>s;
            int t=s[0]-'a';
            g[t].push_back(s);
            cnt[t]++;
        }
        for(int i=0;i<26;i++)
        {
            sort(g[i].begin(),g[i].end());
        }
        while(m--)
        {
            char c;cin>>c;
            int t=c-'a';
            cout<<g[t][now[t]]<<endl;
            now[t]++;
            if(now[t]==cnt[t]) now[t]=0;
        }
        return 0;
    }
    
    • 0
      @ 2026-11-9 21:57:03
      #include<bits/stdc++.h>
      using namespace std;
      vector <string> a[30];
      int t[30];
      int n,k;
      int main()
      {
      	cin>>k>>n;
      	for(int i=1;i<=k;i++){
      		string x; cin>>x;
      		a[x[0]-'a'+1].push_back(x);
      	}
      	for(int i=1;i<=30;i++){
      		sort(a[i].begin(),a[i].end());
      	}
      	for(int i=1;i<=n;i++){
      		char x;cin>>x;
      		bool f=0;
      		cout<<a[x-'a'+1][t[x-'a'+1]]<<endl;
      		t[x-'a'+1]+=1;
      		if(t[x-'a'+1]==a[x-'a'+1].size()){
      			t[x-'a'+1]=0;
      		}
      
      	}	
      	return 0;
      }
      
      • 1

      Information

      ID
      3479
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      3
      Tags
      (None)
      # Submissions
      18
      Accepted
      11
      Uploaded By