| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
sort排序 16MS AC 附代码比较水!
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef struct Node{
string s;
int n;
}Node;
Node node[101];
bool cmp(Node x,Node y)
{
return x.n < y.n;
}
int main()
{
int m,n;
while(cin >> m >> n)
{
for(int i = 0 ; i < n ; i++)
{
cin >> node[i].s;
int cnt = 0;
for(int j = 0 ; j < node[i].s.length() ; j++)
{
for(int k = j+1 ; k < node[i].s.length() ; k++)
{
if(node[i].s[j] > node[i].s[k])
cnt++;
}
}
node[i].n = cnt;
}
sort(node,node+n,cmp);
for(int i = 0 ; i < n ; i++)
cout << node[i].s << endl;
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator