/// Raihan Ruhin /// CSE, Jahangirnagar University. /// Dhaka-Bangladesh. /// id: raihanruhin (topcoder / codeforces / codechef / uva), 3235 (lightoj) /// mail: raihanruhin@ (yahoo / gmail / facebook) /// blog: ruhinraihan.blogspot.com #include<bits/stdc++.h> using namespace std; #define SET(a) memset(a,-1,sizeof(a)) #define CLR(a) memset(a,0,sizeof(a)) #define PI acos(-1.0) #define MOD 1000000007 #define MX 100010 int main() { ios_base::sync_with_stdio(0);cin.tie(0); int kk=1, tc, n, m, cnt; string s; cin>>tc; while(tc--) { cin>>n>>m; vector< pair<int, pair<int, string> > > v; for(int i=0;i<m;i++) { cin>>s; cnt=0; for(int j=0;j<n-1;j++) for(int k=j+1;k<n;k++) if(s[j]>s[k]) cnt++; v.push_back(make_pair(cnt, make_pair(i,s))); } sort(v.begin(), v.end()); if(kk>1) cout<<"\n"; for(int i=0;i<m;i++) cout<<v[i].second.second<<"\n"; kk++; } return 0; }
Saturday, 9 July 2016
DNA Sorting (UVA 612, HDU 1379, POJ 1007, ZOJ 1188, UVALive 5414, Regionals 1998 >> North America - East Central NA)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment