原理,利用multiset元素可重复,自动排序的特性,选用mutilset存放输入的字符串。输入完成后,输出即可。

#include<bits/stdc++.h>
using namespace std;

int main(){
    int n = 0;
    cin >> n;
    string str;
    multiset<string> strS;
    while(n--){
        cin >> str;
        strS.insert(str);
    }
    for(auto s:strS){
        cout << s << endl;
    }
    return 0;
}