题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int a;
cin >> a;
vector<string> lines;
for (int i = 0;i < a;i++) {
string line;
getline(cin, line);
cin >> line;
lines.push_back(line);
}
stable_sort(lines.begin(), lines.end());
for (auto e : lines) {
cout << e << endl;
}
}
// 64 位输出请用 printf("%lld")
原来所谓的按照字典序排列就是直接sort,不过是对于字符串的序列。
不过用sort还是用stable_sort就看个人了。
查看24道真题和解析