【题解】Luogu P1628 【合并序列】

字符串水题一道,string + sort即可

#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<iostream>

namespace OI{
    using std::string;
    using std::sort;
    using std::vector;
    using std::cin;
    using std::cout;
    using std::endl;
}
using namespace OI;

int main(){
    int n;
    scanf("%d",&n);
    
    vector<string> v;
    vector<string> ans;
    
    for(int i = 0;i < n;i++){
        string s;
        cin >> s;
        v.push_back(s);
    }
    
    string T;
    cin >> T;
    
    for(int i = 0;i < n;i++){
        int len = T.length();
        string p = v[i].substr(0,T.length());
        
        if(p == T){
            ans.push_back(v[i]);
        }
    }
    
    sort(ans.begin(),ans.end());
    
    for(int i = 0;i < ans.size();i++){
        cout << ans[i] << endl;
    }
    
    return 0;
}