牛客网题目链接 字符串排序题 先按照长度排序,长度短的在前面,然后再按照字典序排序。
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cctype>
#include <unordered_map>
#include <map>
using namespace std
;
const int N
= 105;
typedef pair
<int, string
> PII
;
bool cmp(string a
, string b
){
if(a
.size() != b
.size()) return a
.size() < b
.size();
return a
< b
;
}
int main() {
int n
;
while(cin
>>n
){
vector
<string
> vt
;
string str
;
for(int i
= 0; i
< n
; i
++){
cin
>>str
;
vt
.push_back(str
);
}
sort(vt
.begin(), vt
.end(), cmp
);
for(auto s
: vt
) cout
<<s
<<endl
;
}
return 0;
}
转载请注明原文地址: https://mac.8miu.com/read-68827.html