题解 | 字符串排序
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n; // 输入单词个数 cin >> n; // 输入单词 vector<string> words(n); for (int i = 0; i < n; ++i) { cin >> words[i]; } // 按字典序排序 sort(words.begin(), words.end()); // 输出排序后的结果 for (const string& word : words) { cout << word << endl; } return 0; }