3120000938


私信TA

用户名:18274728370

访问量:267

签 名:

我是废物!!!

等  级
排  名 6620
经  验 1341
参赛次数 0
文章发表 1
年  龄 0
在职情况 学生
学  校 广东工业大学
专  业 自动化

  自我简介:

TA的其他文章

解题思路:

注意事项:

参考代码:

#include <stdio.h>

#include <stdlib.h>


typedef struct students{

char name[101];

int age;

int core;}st;


void input (st *l)

{

    scanf("%s %d %d",l->name,&l->age,&l->core);

}


void print(st *l){

printf("%s %d %d\n",l->name,l->age,l->core);

}

//冒泡排序

void bubble(st *list,int n){

int i;

st t;

for(i=0;i<n-1;i++)

{

    if(list[i].core>list[i+1].core)

    {

        t=list[i];

        list[i]=list[i+1];

        list[i+1]=t;

    }

    if(list[i].core==list[i+1].core)

    {

        if(strcmp(list[i].name,list[i+1].name)>0)

        {

             t=list[i];

        list[i]=list[i+1];

        list[i+1]=t;

        }

    }

    if(strcmp(list[i].name,list[i+1].name)==0)

    {

        if(list[i].age>list[i+1].age)

        {

            t=list[i];

        list[i]=list[i+1];

        list[i+1]=t;

        }

    }

}


}


void bubblesort(st *list,int n){


int i;

for (i=n;i>1;i--)

    bubble(list,i);


}


void main()

{

    int N;

    while(scanf("%d",&N)!=EOF)

    {

        if(N<=1000&&N>0)

        {st list[N];

    int i;

        for(i=0;i<N;i++)

        {

            input(&list[i]);

            if(getchar()=='\n')

                continue;

        }


    bubblesort(list,N);

    for(i=0;i<N;i++)

        print(&list[i]);

        }

    }






    return 0;

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区