B1004:成绩排名(20')

思路: 用结构体存储。以分数为基准,每次输入数据,更新分数的max和min。

注意:字符串数组大小要大于10,因为最后一位要存'\0',结构体大小要大于100。

代码:

#include<cstdio>
#include<cstring>
struct Student{
	char name[11];  //字符串数组大小都要设大于10,存‘\0’
	char number[11];
	int score;
}Student[10010];  //结构体大小要大于100

int main(){
	int n;
	char name[11];
	char number[11];
	int score,max,min;
	scanf("%d",&n);
	scanf("%s %s %d",&name,&number,&score);
	strcpy(Student[score].name,name);
	strcpy(Student[score].number,number);
	max = score;
	min = score;
	for(int i = 1;i < n;i ++){
		scanf("%s %s %d",&name,&number,&score);
		strcpy(Student[score].name,name);
		strcpy(Student[score].number,number);
		if(score > max) max = score;
		if(score < min) min = score;
	}
	printf("%s %s\n",Student[max].name,Student[max].number);
	printf("%s %s\n",Student[min].name,Student[min].number);
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

全部评论

相关推荐

06-27 18:45
中山大学 Ruby
25届应届毕业生,来广州2个礼拜了,找不到工作,绝望了,太难过了…
应届想染班味:9爷找不到工作只能说明,太摆了或者太挑了。
点赞 评论 收藏
分享
06-12 17:46
门头沟学院 Java
运营你豪哥:来说重点: ​1.项目前置,时间倒序。​​ 2.​项目描述强化结果与量化效果(STAR原则里的R)。​​ ​3.个人技能精炼,明确掌握程度,突出核心。​​ ​4.增加强有力开头的个人总结部分。​​ 5.​优化教育背景(成绩排名)、合并奖项与活动。​​
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务