题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723
#include <iostream> #include <vector> #include<unordered_map> #include<algorithm> using namespace std; vector<string> getResult(vector<string> &strs){ sort(strs.begin(),strs.end(),[](string s1,string s2){ int m=s1.length(); int n=s2.length(); int i=0; int j=0; while(i<m &&j<n){ if(s1[i]==s2[j]){ i++; j++; } else if(s1[i]<s2[j]){ return 1; } else{ return 0; } } if(i>=m){ return 1; } return 0; }); return strs; } int main() { int num{}; cin>>num; string str{}; vector<string> strs{}; while(cin>>str){ strs.push_back(str); } auto re=getResult(strs); for(auto s:strs){ cout<<s<<'\n'; } return 0; } // 64 位输出请用 printf("%lld")