算法每日一题之成绩排序:std:stable_sort对结构体struct排序
来源:互联网 发布:中信超市软件 编辑:程序博客网 时间:2024/05/22 00:36
#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;}
0 0
- 算法每日一题之成绩排序:std:stable_sort对结构体struct排序
- 每日一题之排序算法专题
- [每日一算法]排序之插入排序
- 实战c++中的vector系列--使用sort算法对vector进行排序(对vector<string>排序、使用稳定的排序std::stable_sort())
- 使用std::sort对struct object排序
- 每日实现一算法之插入排序
- 每日一算法之快速排序
- 每日一算法之归并排序
- 每日一算法之计数排序
- 每日一算法之JS冒泡排序
- STL_算法_对所有元素排序(sort、stable_sort)
- 每日一算法--快速排序
- <每日一算法>冒泡排序
- 成绩排序(结构体)
- 成绩排序 (结构体+自定义排序)
- 成绩排序(结构体三级排序)
- 每日一算法之冒泡排序原理及实现
- 每日一算法之选择排序原理及实现
- 关于UITableview下移64的问题
- windows 下配置 Nginx 常见问题
- 解决在项目里引入Spring Security后iframe或者frame所引用的页无法显示的问题
- 手工指定CHANNEL与设置PARALLELISM参数的异同以及FILESPERSET参数的作用
- Linux TC(Traffic Control)框架原理解析
- 算法每日一题之成绩排序:std:stable_sort对结构体struct排序
- java 字符串转化为字符数组的3种方法
- 多线程断点下载
- 特征的转换_04-探索最优特征组合
- iOS标准时间与时间戳相互转换
- mysql中in与exists的性能与效率对比
- View的事件分发机制
- 公共头部和尾部都是html,怎么通过ajax来实现。
- Support V4的拆分