别看我只是一只羊


私信TA

用户名:bkwzsyzy

访问量:3789

签 名:

等  级
排  名 2322
经  验 2271
参赛次数 1
文章发表 23
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

#include<stdio.h>
#include<string.h>
struct stu{
    char name[101];
    int age;
    int score;
};

int main()
{
    int n;
  while (scanf("%d", &n) != EOF)//注意多组输入
    {
    struct stu s[n];
    for (int i = 0; i < n; i++) {
        scanf("%s",s[i].name);
        scanf("%d %d",&s[i].age, &s[i].score);   // 输入学生数据
         
    }
   
    struct stu temp;
    for(int i=n;i>=1;i--){
        for(int j=0;j<i-1;j++){
            if(s[j].score>s[j+1].score){
                temp=s[j];
                s[j]=s[j+1];
                s[j+1]=temp;
            }
        }
    }
    
    for(int i=n;i>=1;i--){
        for(int j=0;j<n;j++){
           if(s[j].score==s[j+1].score&&strcmp(s[j].name,s[j+1].name)>0)
           {
                temp=s[j];
                s[j]=s[j+1];
                s[j+1]=temp; 
               }
            if(s[j].score==s[j+1].score&&strcmp(s[j].name,s[j+1].name)==0&&s[j].age>s[j+1].age)
           {
                temp=s[j];
                s[j]=s[j+1];
                s[j+1]=temp; 
               }
           } 
        
        }
     
    for(int i=0;i<n;i++)printf("%s %d %d\n",s[i].name,s[i].age,s[i].score);
  }    
}


 

0.0分

1 人评分

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

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区