求高手帮忙。。

duliang135 2012-09-29 12:46:43
小弟初学c++。有个问题不太知道答案。麻烦大家帮我解答一下。谢谢。用到参数重载和循环简单点儿就好。。

一共有10个人。提示用户输入1~10的整数。然后输出学号和成绩。第一方阵不包含平均分
3
2011123458 45 32 64
2010345782 34 98 100
2009425342 74 64 21
//下面是自动按照3个学号高低排列的,最后一个数字53,73,47是平均成绩。
2009425342 74 64 21 53
2010345782 34 98 100 73
2011123458 45 32 64 47
//下面是按照平均成绩排列的。
2010345782 34 98 100 73
2009425342 74 64 21 53
2011123458 45 32 64 47
...全文
146 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
duliang135 2012-10-01
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]
引用 4 楼 的回复:
引用 3 楼 的回复:

C/C++ code

#include <stdio.h>
#include <algorithm>
using namespace std;

struct Info
{
char id[11];
int score1,score2,score3,score;
};

Info p[10];
int n;

……
[/Quote]
能写下来吗?
Gloveing 2012-10-01
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
引用 3 楼 的回复:

C/C++ code

#include <stdio.h>
#include <algorithm>
using namespace std;

struct Info
{
char id[11];
int score1,score2,score3,score;
};

Info p[10];
int n;

bool cmp1(con……
[/Quote]
直接呼出?
----------
那你之前之前直接对Info p[10];
进行初始化/赋值
duliang135 2012-10-01
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

C/C++ code

#include <stdio.h>
#include <algorithm>
using namespace std;

struct Info
{
char id[11];
int score1,score2,score3,score;
};

Info p[10];
int n;

bool cmp1(const Info &a,const……
[/Quote]
要求是学号不用再键入了。。直接呼出就可以。。上面那位写的看不懂。。有简单点儿的吗?
duliang135 2012-09-29
  • 打赏
  • 举报
回复
下面是书上的要求。。。
Maximum number of students is 10
Round off below the decimal point of average scores
You don’t need to care Tie-breaking
Insert format of student is important
◦StudentID Score1 Score2 Score3
dpdp_2012 2012-09-29
  • 打赏
  • 举报
回复

#include <stdio.h>
#include <algorithm>
using namespace std;

struct Info
{
char id[11];
int score1,score2,score3,score;
};

Info p[10];
int n;

bool cmp1(const Info &a,const Info &b)
{
if(strcmp(a.id,b.id)<=0)
return 1;
return 0;
}

bool cmp2(const Info &a,const Info &b)
{
return a.score>b.score;
}

void print()
{
for(int i=0;i<n;i++)
printf("%s %d %d %d %d\n",p[i].id,p[i].score1,p[i].score2,p[i].score3,p[i].score);
}

int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%s%d%d%d",p[i].id,&p[i].score1,&p[i].score2,&p[i].score3);
p[i].score=(p[i].score1+p[i].score2+p[i].score3)/3;
}
sort(p,p+n,cmp1);
print();
sort(p,p+n,cmp2);
print();
}
傻X 2012-09-29
  • 打赏
  • 举报
回复
STL
Vector+Sort

就OK了

64,681

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧