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 wenroudeyanhuo at 2024-03-10 21:36:41 on Problem 1007
#include<stdio.h>
#include<string.h>
// #include<stdlib.h>
#include<algorithm>
using namespace std;
struct nu{
    int index;
    int sort;
};
bool cmp1(struct nu a,struct nu b)
{
    return a.sort<b.sort;
}
// int cmp(const void *a,const void *b)
// {
//     return ((struct nu*)a)->sort>((struct nu*)b)->sort;
// }
int algorithm_count(char *s,int n)
{
    int count=0;
    for (int i = 0; i <n-1; i++)
    {
        /* code */
        for (int j = i+1; j < n; j++)
        {
            /* code */
            if(s[i]>s[j])
            {
                count++;
            }
        }
    }
    return count;
    
}
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    char str[101][51];
    struct nu num[51];
    for(int i=0;i<m;i++)
    {
        scanf("%s",str[i]);
        num[i].sort=algorithm_count(str[i],n);
        num[i].index=i;
        //计算该序列的整齐度
    }
    sort(num,num+m,cmp1);
    // qsort(num,m,sizeof(struct nu),cmp);
        // printf("\n");
    for(int i=0;i<m;i++)
    {
        printf("%s\n",str[num[i].index]);
    }

}

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