/* CODEMAN
Arif Khan Nihar
Uva 612- DNA Sorting
*/
using namespace std;
struct match_records{
string t_name;
int n1;
}team_records[101];
bool cmp(const match_records &x, const match_records &y)
{
return x.n1 < y.n1;
}
int sorted(string s1){
int t = 0;
for(int i = s1.size()-1 ;i >= 1 ;i-- ) {
for(int j = 0; j <= i-1 ; j++ ) {
if( s1[j] > s1[j+1] ) {
swap( s1[j] , s1[j+1] ) ;
t++;
}
}
}
return t;
}
int main()
{
int n,i,m,x;
scanf("%d",&n);
while(n--){
scanf("%d %d", &x , &m ) ;
for(i = 0 ;i < m ; i++ ) {
string s;
cin >> s;
team_records[i].t_name = s;
team_records[i].n1 = sorted(s);
}
stable_sort(team_records,team_records+m,cmp);
for(i = 0 ; i < m ; i++) {
cout << team_records[i].t_name << endl;
}
if(n)cout << endl;
}
return 0;
}
Arif Khan Nihar
Uva 612- DNA Sorting
*/
#include<bits/stdc++.h> |
struct match_records{
string t_name;
int n1;
}team_records[101];
bool cmp(const match_records &x, const match_records &y)
{
return x.n1 < y.n1;
}
int sorted(string s1){
int t = 0;
for(int i = s1.size()-1 ;i >= 1 ;i-- ) {
for(int j = 0; j <= i-1 ; j++ ) {
if( s1[j] > s1[j+1] ) {
swap( s1[j] , s1[j+1] ) ;
t++;
}
}
}
return t;
}
int main()
{
int n,i,m,x;
scanf("%d",&n);
while(n--){
scanf("%d %d", &x , &m ) ;
for(i = 0 ;i < m ; i++ ) {
string s;
cin >> s;
team_records[i].t_name = s;
team_records[i].n1 = sorted(s);
}
stable_sort(team_records,team_records+m,cmp);
for(i = 0 ; i < m ; i++) {
cout << team_records[i].t_name << endl;
}
if(n)cout << endl;
}
return 0;
}
No comments:
Post a Comment