机试:成绩排名

问题描述:

代码示例:

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int main(){
	cout << "样例输入" << endl; 
	int n;
	int m;
	cin >> n;
	int nums[n];
	for(int i = 0; i < n; i++){
		cin >> nums[i];
	}
	
//	排序
	for(int i = 0; i < n; i++){//冒泡 
		for(int j = i+1; j < n; j++){
			if(nums[i] < nums[j]){//交换 
				int temp = nums[i];
				nums[i] = nums[j];
				nums[j] = temp;
			}
		}
	}
	
//	去重
	int k = 0;
	for(int i = 1; i < n; i++){
		if(nums[k] != nums[i]){
			nums[++k] = nums[i];
		}
	} 
	
//	遍历
//	for(int i = 0; i <= k; i++){
//		cout << nums[i] << " "; 
//	} //测试成功 
	cin >> m; 
	cout << "样例输出" << endl; 
	if(m <= k+1){
		cout << nums[m-1];
	}else{
		cout << "不存在";
	}
	return 0;
}

运行结果:

相关推荐
liulilittle2 小时前
认识麻将 —— 流水及对账
算法·游戏·lua·对账·流水·资金·玩法
郝学胜-神的一滴5 小时前
Effective Python 条款44:善用属性注解
开发语言·c++·vscode·python·算法·stl
青少儿编程课堂1 天前
第十八届蓝桥杯青少组图形化真题:校园分形雪花绘制解析(全国青少年信息素养大赛·电子学会图形化考级冲刺)
c++·python·算法·bfs·信息学竞赛
geovindu1 天前
python: KNeighborsClassifier K
开发语言·后端·python·算法
让我们一起加油好吗1 天前
【数据结构】线段树详解
数据结构·c++·算法·线段树·洛谷
凌冰_1 天前
数据结构 - 队列(五)
数据结构·算法·软件工程
让我们一起加油好吗1 天前
【数据结构】ST 表
数据结构·c++·算法·动态规划·洛谷·st表
让我们一起加油好吗1 天前
【算法刷题】LeetCode 力扣 Hot 100 刷题记录
数据结构·c++·算法·leetcode·面试·笔试
lisw052 天前
稀疏算法概述!
算法·机器人·无人机