HDU 1718 Rank (排序)
排序 HDU RANK
2023-09-11 14:17:19 时间
题意:给你n个学号和成绩,并且给定一个学号,让找这个学号是多少名。
析:用个结构体,按成绩排序,然后找那个学号,这个题有一个小坑,那就是并列的情况,
可能并列多少名,这个要考虑一下,其他的easy!
代码如下:
#include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <cstring> #include <map> #include <cctype> using namespace std; const int maxn = 1000 + 5; struct node{ int id, score; bool operator < (const node &p) const { return score > p.score; } }; node a[maxn]; int main(){ // freopen("in.txt", "r", stdin); int ID; while(scanf("%d", &ID) == 1){ int indx = 0; while(true){ scanf("%d %d", &a[indx].id, &a[indx].score); if(!a[indx].id) break; ++indx; } sort(a, a+indx); for(int i = 0; i < indx; ++i) if(a[i].id == ID){ for(int j = i; j >= 0; --j) if(a[j].score != a[i].score){ printf("%d\n", j+2); break; } break; } } return 0; }
相关文章
- 排序的基本概念
- iOS sort array 数组排序里面的对象
- 排序算法--快速排序(QuickSort)、 3区快速排序(3 Way QuickSort)原理、适用场景及代码示例
- PHP 两个多维数组根据某个键的值进行组合排序的几种思路
- 确定比赛名次 HDU - 1285 (拓扑排序)
- 看动画学算法之:排序-count排序
- C语言循环结构及数组排序的综合应用——冒泡、插入、选择排序棒图显示and两个超长数相乘
- 【蓝桥杯Java组】Java选手应知应会的sort排序API详解
- 【剑指offer】37数字在排序数组中出现的次数
- 计数排序、桶排序python实现
- hdu 4857 逃生 (拓扑排序+保证最小在前面)
- 我的Java开发学习之旅------>Java经典排序算法之归并排序
- Lambda 动态表达式(排序)
- Unity中影响UI排序的组件
- 算法补天系列之——堆和桶(以及部分排序问题)