3 solutions

  • -1
    @ 2026-9-28 13:24:59
    #include<bits/stdc++.h>
    using namespace std;
    const int N=50010;
    string s[N];
    int order[300];
    bool cmp(string a,string b)
    {
    	for(int i=0;i<a.size()&&i<b.size();i++)
    	{
    		if(a[i]!=b[i]) return order[a[i]]<order[b[i]];
    	}
    	return a.size()<b.size();
    }
    int main()
    {	
    	string s1;
    	int n;
    	cin>>s1>>n;
    	for(int i=0;i<s1.size();i++)//遍历整个序列 
    	{
    		order[s1[i]]=i;	
    	} 
    	for(int i=0;i<n;i++) //输入需要排序的字符串 
    	{
    		cin>>s[i];
    	}
    	sort(s,s+n,cmp);//将字符串按照给定的规则排序
    	for(int i=0;i<n;i++)
    	{
    		cout<<s[i]<<endl;
    	}
    	return 0;
    }
    
    
    

    Information

    ID
    2617
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    3
    Tags
    # Submissions
    12
    Accepted
    6
    Uploaded By