机试:成绩排名

问题描述:

代码示例:

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;
}

运行结果:

相关推荐
一路往蓝-Anbo6 小时前
C语言从句柄到对象 (三) —— 抛弃 Malloc:静态对象池与索引句柄的终极形态
c语言·开发语言·数据结构·stm32·单片机·算法
fantasy_arch6 小时前
SVT-AV1 B帧决策和mini-GOP决策分析
算法·av1
声声codeGrandMaster6 小时前
逻辑回归-泰坦尼克号
算法·机器学习·逻辑回归
mu_guang_7 小时前
算法图解2-选择排序
数据结构·算法·排序算法
xiaowu0807 小时前
IEnumerable、IEnumerator接口与yield return关键字的相关知识
java·开发语言·算法
报错小能手7 小时前
数据结构 b+树
数据结构·b树·算法
元亓亓亓7 小时前
LeetCode热题100--64. 最小路径和--中等
算法·leetcode·职场和发展
mit6.8247 小时前
回溯+位运算|前缀和优化背包
算法
努力学算法的蒟蒻8 小时前
day49(12.30)——leetcode面试经典150
算法·leetcode·面试
天赐学c语言8 小时前
12.30 - 合并区间 && C++中class和C语言中struct的区别
c语言·c++·算法·leecode