解法一、函式庫
✅ 完整代碼
評分結果(參考) : AC (2ms, 344KB)
#include<bits/stdc++.h>
using namespace std;
bool comp(string& a, string& b){
if(a.size() != b.size())
return a.size() < b.size();
return a < b;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, size = 0;
cin >> n;
vector<string> v(n);
for(string& s : v){
cin >> s;
size = max(size, (int)s.size());
}
sort(v.begin(), v.end(), comp);
for(string& s : v) cout << setw(size) << s << "\n";
return 0;
}