• 学生信息录入(学号 姓名 成绩),并按学号查找。


    #include<stdio.h>
    #include<stdlib.h>
    #define N 100
    struct student
    {
            char num[9];
            char name[20];
            int score;
    };
    void imput(struct student stu[],int n)
    {
            int i;
            printf("依次输入学生学号、姓名、成绩:
    ");
            for(i=0;i<n;i++)
            {
                    scanf("%s",stu[i].num);
                    scanf("%s",stu[i].name);
                    scanf("%d",&stu[i].score);
            }
    }
    void sort(struct student st[],int n)
    {
            struct student t;
            int i,j,k;
            for(i=0;i<n-1;i++)
            {
                    k=i;
                    for(j=i+1;j<n;j++)
                    {
                            if(st[k].score<st[j].score)
                            k=j;
                    }
                    if(k!=i)
                    {
                            t=st[i];st[i]=st[k];st[k]=t;
                    }
            }
    
    }
    void output(struct student stu[],int n)
    {
            printf("排序后的信息为:
    ");
            int i;
            for(i=0;i<n;i++)
            {
                    printf("%s ",stu[i].num);
                    printf("%s ",stu[i].name);
                    printf("%d ",stu[i].score);
                    printf("
    ");
            }
    
    }
    void serch(struct student st[],int n)
    {
            printf("请输入学生8位学号进行查找:
    ");
            int i,k=-1;
            char c[9];
            scanf("%s",c);
            for(i=0;i<n;i++)
            {
                    if(strcmp(st[i].num,c)==0)
                    {
                             k=i;
                             printf("%s ",st[i].num);
                             printf("%s ",st[i].name);
                             printf("%d ",st[i].score);
                             printf("
    ");
    
                    }
            }
            if(k==-1)printf("该学号不存在。");
    
    }
    void main()
    {
            struct student st[N];
            int n;
            printf("请输入学生数量: ");
            scanf("%d",&n);
            imput(st,n);
            sort(st,n);
            output(st,n);
            serch(st,n);
    }
  • 相关阅读:
    AC自动机学习笔记(模板)
    codeforces1328E
    Codeforces 1288E- Messenger Simulator (树状数组)
    线性基小记
    HDU3949
    矩阵快速幂小记
    5E
    5D
    5C
    5B
  • 原文地址:https://www.cnblogs.com/purplec/p/5549926.html
Copyright © 2020-2023  润新知