string比较大小就是按照字典序比较的,所以可以直接使用sort
字串的连接最长路径查找
http://www.nowcoder.com/questionTerminal/5af18ba2eb45443aa91a11e848aa6723
#include <bits/stdc++.h> using namespace std; int main() { int n; /* bool (*strcompare)(const string &a, const string &b) = [](const string &a, const string &b)->bool{ int i(0); for(;i<a.length()&&i<b.length();i++){ if(a[i]==b[i]) continue; if(a[i]<b[i]) return true; else return false; } if(i==a.length()) return true; return false; }; */ while(cin>>n){ vector<string> data; while(n--){ string instr;cin>>instr; data.push_back(instr); } //sort(data.begin(),data.end(),strcompare); sort(data.begin(),data.end()); for(auto str:data){ cout<<str<<endl; } } return 0; }
我蠢比了,还自己写了一个比较的函数