国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

算法每日一題之成績排序:std:stable_sort對結構體struct排序

2019-11-11 03:12:28
字體:
來源:轉載
供稿:網友
#define _CRT_SECURE_NO_WARNINGS#include <stdlib.h>#include <string.h>#include <stdio.h>#include <iostream>#include <vector>#include <algorithm>using namespace std;typedef struct Student{	char name[256];	int score;	int sore_type;} Student;bool my_compare(const Student* stu1, const Student* stu2){	if (stu1->sore_type == 0)	{		return stu1->score > stu2->score;	}	else	{		return stu1->score < stu2->score;	}}//https://www.nowcoder.com/PRactice/0383714a1bb749499050d2e0610418b1?tpId=40&tqId=21333&tPage=1&rp=1&ru=/ta/kaoyan&qru=/ta/kaoyan/question-ranking//c/c++之成績排序:std:stable_sort對結構體struct排序。/**查找和排序題目:輸入任意(用戶,成績)序列,可以獲得成績從高到低或從低到高的排列,相同成績都按先錄入排列在前的規則處理。例示:jack      70peter     96Tom       70smith     67從高到低  成績peter     96jack      70Tom       70smith     67從低到高smith     67Tom       70jack      70peter     96輸入描述:輸入多行,先輸入要排序的人的個數,然后輸入排序方法0(降序)或者1(升序)再分別輸入他們的名字和成績,以一個空格隔開輸出描述:按照指定方式輸出名字和成績,名字和成績之間以一個空格隔開輸入例子:30fang 90yang 50ning 70輸出例子:fang 90ning 70yang 50*/int main(){	int count;	//循環處理多個測試用例	while (scanf("%d", &count) != EOF)	{		int type;		scanf("%d", &type);		std::vector<Student*> list;		for (int i = 0; i < count; i++)		{			char name[256] = { 0 };			int score;			scanf("%s", name);			scanf("%d", &score);			Student* stu = new Student();			stu->score = score;			stu->sore_type = type;			strcpy(stu->name, name);			list.push_back(stu);		}		//std::sort(list.begin(), list.end(), my_compare);//存在問題		std::stable_sort(list.begin(), list.end(), my_compare);		for (int i = 0; i < count; i++)		{			Student* stu = list.at(i);			printf("%s %d/n", stu->name, stu->score);		}	}	return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 福海县| 连江县| 高要市| 隆化县| 兴仁县| 准格尔旗| 盐池县| 平凉市| 公主岭市| 江川县| 镇康县| 呼玛县| 阳曲县| 芷江| 辉南县| 瑞安市| 历史| 三门峡市| 横峰县| 云林县| 阳山县| 普兰店市| 雷山县| 盐亭县| 玉山县| 平湖市| 兴和县| 正镶白旗| 迁西县| 和硕县| 邵阳市| 渑池县| 珲春市| 金寨县| 晋宁县| 连山| 墨竹工卡县| 六枝特区| 六枝特区| 连平县| 平乐县|