| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1972 人关注过本帖
标题:关于学生成绩表的指针运算
只看楼主 加入收藏
零号小白菜
Rank: 1
等 级:新手上路
帖 子:18
专家分:8
注 册:2019-11-10
结帖率:75%
收藏
 问题点数:0 回复次数:4 
关于学生成绩表的指针运算
这道题怎么去做呢?
Description 输入10个学生,每个学生的数据包括学号、姓名、3门课的成绩。定义结构体类型表示学生类型,输入10个学生的数据,
计算每个学生的平均成绩。按平均成绩由高到低输出所有学生信息,成绩相同时按学号从小到大输出。

#include <stdio.h>

struct data
{
_______________________
};

int main()
{
    int i,j;
    struct data stu[10],tmp;
    for(i=0; i<10; i++)
    {
_______________________
    }
    for(i=0; i<9; i++)
        for(j=0; j<9-i; j++)
        {
_______________________
        }
    for(i=0; i<10; i++)
    {
        printf("%d %s %.0lf %.0lf %.0lf\n", stu[i].num, stu[i].name, stu[i].score[0], stu[i].score[1], stu[i].score[2]);
    }
    return 0;
}



输入格式 10个学生信息,每行一个学生



输出格式 如题



输入样例 1 aaa 50 60 70
2 bbb 50 50 50
3 ccc 60 70 80
4 ddd 40 40 40
5 eee 70 80 90
6 fff 30 30 30
7 ggg 80 90 100
8 hhh 20 20 20
9 iii 100 100 100
10 jjj 10 10 10





输出样例 9 iii 100 100 100
7 ggg 80 90 100
5 eee 70 80 90
3 ccc 60 70 80
1 aaa 50 60 70
2 bbb 50 50 50
4 ddd 40 40 40
6 fff 30 30 30
8 hhh 20 20 20
10 jjj 10 10 10
搜索更多相关主题的帖子: 学生 输入 成绩 for stu 
2019-12-10 12:23
零号小白菜
Rank: 1
等 级:新手上路
帖 子:18
专家分:8
注 册:2019-11-10
收藏
得分:0 
我写的这个有什么不对吗?
#include <stdio.h>

struct data
{
   int num;
   char name;
   double score[3];
};

int main()
{
    int i,j;
    struct data stu[10],tmp;
    for(i=0; i<10; i++)
    {
       scanf("%d",&stu[i].num);
       scanf("%s",&stu[i].name);
       for(j=0;j<3;j++)
       {
           scanf("%lf",&stu[i].score[j]);
       }

    }
    for(i=0; i<9; i++)
        for(j=0; j<9-i; j++)
        {
        double a1,a2;
       a1=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3;
       a2=(stu[j].score[0]+stu[j].score[1]+stu[j].score[2])/3;
          if(a1>a2)
          {
              tmp=stu[i];
              stu[i]=stu[j];
              stu[j]=tmp;

          }
          else if(a1==a2)
          {
              if(stu[i].num>stu[j].num)
              {
                  tmp=stu[i];
                  stu[i]=stu[j];
                  stu[j]=tmp;
              }
          }
        }
    for(i=0; i<10; i++)
    {
        printf("%d %s %.0lf %.0lf %.0lf\n", stu[i].num, stu[i].name, stu[i].score[0], stu[i].score[1], stu[i].score[2]);
    }
    return 0;
}
2019-12-10 12:47
零号小白菜
Rank: 1
等 级:新手上路
帖 子:18
专家分:8
注 册:2019-11-10
收藏
得分:0 
终于对了
#include <stdio.h>

struct data
{
   int num;
   char name[20];
   double score[3];
};

int main()
{
    int i,j;
    struct data stu[10],tmp;
    for(i=0; i<10; i++)
    {
    scanf("%d %s %lf %lf %lf", &stu[i].num, stu[i].name, &stu[i].score[0], &stu[i].score[1], &stu[i].score[2]);

    }
    for(i=0; i<9; i++)
        for(j=0; j<9-i; j++)
        {
        double a1,a2;
       a1=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3;
       a2=(stu[9-j].score[0]+stu[9-j].score[1]+stu[9-j].score[2])/3;
          if(a1<a2)
          {
              tmp=stu[i];
              stu[i]=stu[9-j];
              stu[9-j]=tmp;

          }
          else if(a1==a2)
          {
              if(stu[i].num>stu[j].num)
              {
                  tmp=stu[i];
                  stu[i]=stu[j];
                  stu[j]=tmp;
              }
          }
        }
    for(i=0; i<10; i++)
    {
        printf("%d %s %.0lf %.0lf %.0lf\n", stu[i].num, stu[i].name, stu[i].score[0], stu[i].score[1], stu[i].score[2]);
    }
    return 0;
}
2019-12-10 13:06
零号小白菜
Rank: 1
等 级:新手上路
帖 子:18
专家分:8
注 册:2019-11-10
收藏
得分:0 
回复 3楼 零号小白菜
上面那个有一步错了,这个是正确的版本!
但是如果有大佬有更简便的方法的话也不妨分享一下
#include <stdio.h>

struct data
{
   int num;
   char name[20];
   double score[3];
};

int main()
{
    int i,j;
    struct data stu[10],tmp;
    for(i=0; i<10; i++)
    {
    scanf("%d %s %lf %lf %lf", &stu[i].num, stu[i].name, &stu[i].score[0], &stu[i].score[1], &stu[i].score[2]);

    }
    for(i=0; i<9; i++)
        for(j=0; j<9-i; j++)
        {
        double a1,a2;
       a1=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3;
       a2=(stu[9-j].score[0]+stu[9-j].score[1]+stu[9-j].score[2])/3;
          if(a1<a2)
          {
              tmp=stu[i];
              stu[i]=stu[9-j];
              stu[9-j]=tmp;

          }
          else if(a1==a2)
          {
              if(stu[i].num>stu[j].num)
              {
                  tmp=stu[i];
                  stu[i]=stu[j];
                  stu[j]=tmp;
              }
          }
        }
    for(i=0; i<10; i++)
    {
        printf("%d %s %.0lf %.0lf %.0lf\n", stu[i].num, stu[i].name, stu[i].score[0], stu[i].score[1], stu[i].score[2]);
    }
    return 0;
}
收到的鲜花
  • 静夜思2019-12-10 13:31 送鲜花  5朵   附言:分享精神值得肯定
  • bcbbcclbbc2019-12-11 09:14 送鲜花  5朵  
2019-12-10 13:27
零号小白菜
Rank: 1
等 级:新手上路
帖 子:18
专家分:8
注 册:2019-11-10
收藏
得分:0 
回复 4楼 零号小白菜
哈哈哈哈哈哈哈哈哈
复制错误了
最后那个else if那里应该是
else if(a1==a2)
          {
              if(stu[i].num>stu[j].num)
              {
                  tmp=stu[i];
                  stu[i]=stu[9-j];
                  stu[9-j]=tmp;
              }
果然,太困了还是要休息休息的。
2019-12-10 13:34
快速回复:关于学生成绩表的指针运算
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015982 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved