Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

sort排序 16MS AC 附代码

Posted by kingsword at 2011-08-25 16:06:21 on Problem 1007
比较水!

#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator