支持任意数目城市,c++代码:
#include
#include
#include
using namespace std;
bool compare(string first, string second)
{
unsigned int i=0;
while ( (i
if (first[i]
++i;
}
if (first.length()
}
int main()
{
int n, i;
list
list
string city;
cout << "输入将要输入的城市总数: ";
cin >> n;
cout << "请输入" << n << "个城市:" << endl;
for(i = 0; i < n; i ++) {
cin >> city;
mylist.push_back(city);
}
mylist.sort(compare);
cout << "排序后: " << endl;
for (it=mylist.begin(); it!=mylist.end(); ++it)
cout << *it << endl;
return 0;
}