zoukankan      html  css  js  c++  java
  • 1757: 成绩稳定的学生(武汉科技大学结构体oj)

    #include<stdio.h>
    #include<string.h>
    struct student
    {
    long no;
    char name[9];
    int ch[20];
    int count;//多定义一个count来看某个学生是不是每科的成绩都大于平均值
    }
    read(struct student stu[],int n,int m)
    {
    int i,j;
    for(i=0;i<n;i++)
    {
    scanf("%ld %s",&stu[i].no,&stu[i].name);//分别读入,有缓冲区
    for(j=0;j<m;j++)
    {
    scanf("%d",&stu[i].ch[j]);
    }
    stu[i].count=0;
    }
    }
    int solved(struct student stu[],int n,int m,int result[])
    {
    memset(result,-1,100);//方便后面的while循环
    int average,sum=0,i,j,k,q=0,t,num=0;
    for(i=0;i<m;i++)
    {
    for(j=0;j<n;j++)
    {
    sum+=stu[j].ch[i];
    }
    average=sum/n;
    for(k=0;k<n;k++)
    {
    if(stu[k].ch[i]>average) stu[k].count++;
    }
    sum=0;
    }
    for(i=0;i<n;i++)
    {
    if(stu[i].count==m)
    {
    result[q]=i;//把stu[i]中的i值存到result 数组里。
    q++;
    num++;
    }
    }
    return num;
    }
    void write(struct student stu[],int t,int m,int result[])
    {
    int i=0,j;
    printf("num=%d ",t);
    while(result[i]!=-1)
    {
    printf("%ld %s ",stu[result[i]].no,stu[result[i]].name);//分开输出
    for(j=0;j<m-1;j++) printf("%d ",stu[result[i]].ch[j]);
    printf("%d ",stu[result[i]].ch[m-1]);
    i++;
    }
    }
    int main()
    {
    int n,m,resdent stu[100];
    while(scanult[100],t;
    struct stuf("%d%d",&n,&m)!=EOF)
    {
    read(stu,n,m); //读入n个学生的数据
    t=solved(stu,n,m,result); //将成绩稳定的学生编号存到数组result中,返回成绩稳定的学生人数
    write(stu,t,m,result); //输出t个成绩稳定的学生的信息
    }
    return 0;
    }

  • 相关阅读:
    Intersection
    B-number
    Intersecting Lines
    Segments
    G. Swapping Places
    Toy Storage
    TOYS
    哈密顿绕行世界问题
    java试题复盘——11月25日
    java试题复盘——11月13日
  • 原文地址:https://www.cnblogs.com/cy846586184/p/12287166.html
Copyright © 2011-2022 走看看