大整数排序【华中科技大学】

mac2022-06-30  18

牛客网题目链接 字符串排序题 先按照长度排序,长度短的在前面,然后再按照字典序排序。

#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; }
最新回复(0)