题解(排序)
2025-09-29 10:08:31
发布于:浙江
8阅读
0回复
0点赞
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool imc(string s) {
bool hasUpper = false, hasLower = false;
for (char c : s) {
if (isupper(c)) hasUpper = true;
else hasLower = true;
if (hasUpper && hasLower) return true;
}
return false;
}
bool cmp(string a,string b) {
bool am = imc(a);
bool bm = imc(b);
if (am != bm) {
return !am;
}
if (a.length() != b.length()) {
return a.length() < b.length();
}
return a < b;
}
int main() {
int n;
cin >> n;
string strs[114514];
for (int i = 0; i < n; ++i) cin >> strs[i];
sort(strs, strs+n ,cmp);
for (string s : strs) cout << s << '\n';
return 0;
}
这里空空如也
有帮助,赞一个