OJ平台作业:1.10-03:成绩排序

 状态:Compile Error

估计是strcpy使用使得编译错误,本人用的vs2022关闭了SDL编译成功了,所以我们可以编写一个函数代替strcpy,本人太懒就没写(滑稽)

#include<iostream>
#include<string>
using namespace std;
class information
{
private:
	char name[20];
	int score;
public:
	void get()
	{
		cin >> name >> score;
	}
	void show()
	{
		cout << name << " " << score << endl;
	}
	int Score()
	{
		int a;
		a = score;
		return a;
	}
	char Name()
	{
		char a;
		a = name[0];
		return a;
	}
	friend void exchange(information& a, information& b)
	{
		information s;
		s.score = a.score;
		strcpy(s.name, a.name);
		a.score = b.score;
		strcpy(a.name, b.name);
		b.score = s.score;
		strcpy(b.name, s.name);
	}
};
int main()
{
	information student[20];
	int n, i = 0, j = 0;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		student[i].get();
	}
	for (i = 0; i < n - 1; i++)
	{
		for (j = 0; j < n - 1 - i; j++)
		{
			if (student[j].Name() < student[j + 1].Name())
			{
				exchange(student[j], student[j + 1]);
			}
		}
	}
	for (i = 0; i < n - 1; i++)
	{
		for ( j = 0; j < n - 1 - i; j++)
		{
			if (student[j].Score() < student[j + 1].Score())
			{
				exchange(student[j], student[j + 1]);
			}
		}
	}
	cout << "排序后:" << endl;
	for (i = 0; i < n; i++)
	{
		student[i].show();
	}
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值