许诺 • 13天前
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool compareStrings(const string &a, const string &b) {
const char *ptrA = a.c_str();
const char *ptrB = b.c_str();
while (*ptrA && *ptrB) {
if (*ptrA != *ptrB) {
return *ptrA < *ptrB;
}
ptrA++;
ptrB++;
}
return *ptrA == '\0' && *ptrB != '\0';
}
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(), compareStrings);
for (const string &word : words) {
cout << word << '\n';
}
return 0;
}
评论:
请先登录,才能进行评论