PAT Basic Level Practice 1004.成绩排名(c++)

分析:本题考察的是结构体,用类也可以,最终我使用了结构体

题意:输入一个数字代表学生的数目(<10);

          名字和学号小于10个字符串,成绩在0到100之间;

           最后换行输出最好学生的名字学号以及最差学生的名字学号。

注意:提交网站时,注意scanf_s, printf_s, strcpy_s。


#include<cstdio>
#include<string.h>
struct Student{
	char name[11];
	char id[11];
	int grade;
}temp,max,min;

int main()
{
	int n;
	max.grade = -1;
	min.grade = 101;
	scanf_s("%d", &n);
	while (n--)
	{
		scanf_s("%s%s%d", temp.name, 11,temp.id, 11,&temp.grade);
		if (temp.grade > max.grade)
		{
			strcpy_s(max.name, temp.name);
			strcpy_s(max.id, temp.id);
			max.grade = temp.grade;
		}
		if (temp.grade < min.grade)
		{
			strcpy_s(min.name, temp.name);
			strcpy_s(min.id, temp.id);
			min.grade = temp.grade;
		}
	}
	printf_s("%s %s\n", max.name, max.id);
	printf_s("%s %s\n", min.name, min.id);
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值