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

狂WA, 哪位帮忙看看

Posted by 417370112 at 2006-12-23 17:44:07 on Problem 1007
#include <stdlib.h>
const int N = 60;
const int M = 101;

int n, m;

struct node
{
       char string[N];
       int num;
};
struct node str[M];

void cacu (struct node &A)
{
     int i, j;
     for (i = 0; i < n - 1; i ++)
     for (j = i + 1; j < n; j ++)
     {
         if (A.string[i] <= A.string[j])
         {
                         A.num ++;//统计正常顺序数目 
         }
     }
}
int cmp (const void *p, const void *q)
{
    struct node *a, *b;
    a = (struct node *)p;
    b = (struct node *)q;
    return a->num < b->num;
}
int main ()
{
    int i, j;
    scanf ("%d %d", &n, &m);
    for (i = 0; i < m; i ++)
    {
        scanf ("%s", str[i].string);
        str[i].num = 0;
        cacu (str[i]);
    }
    qsort (str, m, sizeof (str[0]), cmp);
    for (i = 0; i < m; i ++)
    {
        printf ("%s\n", str[i].string);
    }    
    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