zoukankan      html  css  js  c++  java
  • 1752: 学生数据排序

    #include<stdio.h>
    struct student
    {
    char name[9];
    long no;
    int score[4];
    };
    void input(struct student stu[100],int n)
    {
    int i;
    for(i=1;i<=n;i++)
    {
    scanf("%ld %s %d %d %d",&stu[i].no,&stu[i].name,&stu[i].score[1],&stu[i].score[2],&stu[i].score[3]);
    stu[i].score[0]=stu[i].score[1]+stu[i].score[2]+stu[i].score[3];
    }
    return;
    }
    void sort(struct student stu[100],int n)
    {
    struct student t;
    int i,j;
    for(i=1;i<=n;i++)
    for(j=i+1;j<=n;j++)
    {
    if(stu[i].score[0]<stu[j].score[0] || stu[i].score[0]==stu[j].score[0] && stu[i].no>stu[j].no)
    {
    t=stu[i];
    stu[i]=stu[j];
    stu[j]=t;
    }
    }
    return;
    }
    void print(struct student stu[100],int n)
    {
    int i;
    for(i=1;i<=n;i++)
    {
    printf("%d ",i);
    printf("%ld %s %d %d %d %d ",stu[i].no,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3]);
    }
    return;
    }
    int main()
    {
    int n;
    struct student stu[100];
    while(scanf("%d",&n)!=EOF)
    {
    input(stu,n); //读入n个学生的数据
    sort(stu,n); //按照总分降序排序,如果总分相同的学号小的在前面
    print(stu,n); //输出n个学生的信息
    }
    return 0;
    }

  • 相关阅读:
    环境变量的配置
    java语言概述
    快捷键,功能键及常用的DOS命令
    html介绍
    Java web学习框架
    线程的使用
    Task类(任务)
    Parallel类(简化Task 操作)
    文件及数据流技术
    泛型的使用
  • 原文地址:https://www.cnblogs.com/cy846586184/p/12269773.html
Copyright © 2011-2022 走看看