caibird


私信TA

用户名:wangduoduo

访问量:135

签 名:

等  级
排  名 35756
经  验 387
参赛次数 3
文章发表 2
年  龄 0
在职情况 学生
学  校 河北工程大学
专  业

  自我简介:

TA的其他文章

#include<iostream>
using namespace std;
#include<vector>
#include<string>
#include<algorithm>
class Student{
public:
	Student(string name, int age, int score)
	{
		this->m_name = name;
		this->m_age = age;
		this->m_score = score;
	}
	string m_name;
	int m_age;
	int m_score;
};

bool mycompare(Student s,Student b)
{
	if (s.m_score == b.m_score)
	{
		if (s.m_name == b.m_name)
		{
			return s.m_age < b.m_age;
		}
		return s.m_name < b.m_name;
	}
	return s.m_score < b.m_score;
}

int main()
{
    int N;
	int  age, score;
	string name;
	vector<Student> v;
	
	while (cin >> N)
	{
		//输入学生数据
		for (int i = 0; i < N; i++)
		{
			cin >> name;
			cin >> age;
			cin >> score;
			Student S(name, age, score);
			//将学生数据插入到容器中
			v.push_back(S);
		}
		//自定义排序
		sort(v.begin(), v.end(), mycompare);

		//打印容器内数据
		for (vector<Student>::iterator it = v.begin(); it != v.end(); it++)
		{
			cout << (*it).m_name << " " << (*it).m_age << " " << (*it).m_score << endl;
		}
		v.clear();
	}
	return 0;
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区