NYOJ283 对称排序
稳定排序。
附ac代码:
#include <iostream> #include <string> #include <vector> using namespace std; int main(){ vector<string> vec; int n, i, j, count = 1, m; string t; while(cin >> n, n){ for(i = 0; i != n; ++i){ cin >> t; vec.push_back(t); } //排序 m = n; while(m > 1){ for(j = 0; j < m - 1; ++j) if(vec[j].length() > vec[j + 1].length()) t = vec[j], vec[j] = vec[j + 1], vec[j + 1] = t; --m; } cout << "SET " << count++ << endl; for(i = 0; i < vec.size(); i += 2){ cout << vec[i] << endl; } if(i == n) --i; else i -= 3; while(i > 0){ cout << vec[i] << endl; i -= 2; } vec.clear(); } return 0; }