蓝桥杯输入学生姓名,性别,年龄,成绩进行排序输出

PS:该程序是在VS2013下运行的,在蓝桥杯练习系统上也通过了测试。 

#include
#include
using namespace std;

typedef struct student
{
	string _name;
	string _sex;
	int _age;
	int _score;
}stu;

int main()
{
	stu arr[1000];
	int n;
	cin >> n;
	int i;
	for (i = 0; i < n; i++)
	{
		cin >> arr[i]._name >> arr[i]._sex >> arr[i]._age >> arr[i]._score;
	}
	int j, k;
	stu tmp;
	for (j = 1; j < n; j++){
		for (k = 0; k < n - j; k++){
			if (arr[k]._score > arr[k + 1]._score)
			{
				tmp = arr[k];
				arr[k] = arr[k + 1];
				arr[k + 1] = tmp;
			}
		}
	}
	for ( i = 0; i < n; i++)
	{
		cout << arr[i]._name << " " << arr[i]._sex << " " << arr[i]._age << " " << arr[i]._score<

 

你可能感兴趣的:(C++代码,简单算法题)