#include<iostream> #include<cstdio> #include<vector> #include<cstdlib> #include<algorithm> #include<utility> using namespace std; bool cmp(const pair<int, string>& a,const pair<int, string>& b) { return a.first < b.first; } int val(const string& a) { int len = a.size(), cont = 0; for (int i = 0; i < len; i++) for (int j = i + 1; j < len; j++) if(a[i] > a[j]) cont++; return cont; } int main() { /*freopen("in.in", "r", stdin); freopen("out.out", "w", stdin);*/ string linea; int test, n, m; bool first = true; getline(cin, linea); test = atoi(linea.c_str()); getline(cin, linea); while (test--) { getline(cin, linea); sscanf(linea.c_str(), "%d %d", &n, &m); vector<pair <int, string> > lista(m); for (int i = 0; i < m; i++) { getline(cin, linea); lista[i] = make_pair(val(linea), linea); } getline(cin, linea); stable_sort(lista.begin(), lista.end(), cmp); if(!first) printf("\n"); first = false; for (int i = 0; i < m; i++) { printf("%s\n", lista[i].second.c_str()); } } return 0; }
lunes, 16 de enero de 2012
612 - DNA Sorting - UVA
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario