#include <cstdio> #include <iostream> #include <algorithm> using namespace std; struct line { string words; int len; bool operator< (const line& t) const { return len < t.len; } }; int main() { int n; while (cin>>n) { getchar();//将n后面的'\n'从缓冲区中读走,不然会被后面的getline()读走 line* arr = new line[n]; string str; int index = 0; while (getline(cin, str) && str != "stop") { line l; l.words = str; l.len = str.size(); arr[index++] = l; if (index == n) break; } sort(arr, arr + index); for (int i = 0; i < index; i++) cout << arr[i].words << endl; } return 0; }