c++ topk问题

 

https://blog.csdn.net/SmartDemo/article/details/107572238

https://blog.csdn.net/wuqingshan2010/article/details/108508676

	int K = 5;
	std::vector scores;

	scores.push_back(0.56);// 压入元素
	scores.push_back(10.56);// 压入元素
	scores.push_back(01.56);// 压入元素
	scores.push_back(02.56);// 压入元素
	scores.push_back(05.56);// 压入元素
	scores.push_back(50.56);// 压入元素
	scores.push_back(30.56);// 压入元素
	std::vector idx(scores.size());
	//std::iota(idx.begin(), idx.end(), 0);
	std::sort(idx.begin(), idx.end(),
		[&scores](size_t index_1, size_t index_2) { return scores[index_1] > scores[index_2]; });
	// 获取K值
	int k_num = std::min(scores.size(), K);
	std::vector scores_K;
	int idx_j = 0;
	for (int j = 0; j < k_num; ++j) 

你可能感兴趣的:(c++入门宝典)