C++ 算法:计算红红成绩排名
#include
int main() { int n; std::cin >> n;
std::vector<int> scores(n);
for (int i = 0; i < n; i++) {
std::cin >> scores[i];
}
int redScore;
std::cin >> redScore;
scores.push_back(redScore);
std::sort(scores.begin(), scores.end(), std::greater<int>());
int redRank = std::find(scores.begin(), scores.end(), redScore) - scores.begin() + 1;
std::cout << redRank << std::endl;
return 0;
}
原文地址: http://www.cveoy.top/t/topic/pFr4 著作权归作者所有。请勿转载和采集!