Answers for "climbing the leaderboard"

PHP
0

climbing the leaderboard

int n, m, score;
cin >> n;
vector<int> scores(n);
copy_n(istream_iterator<int>(cin), n, begin(scores));
scores.erase(unique(begin(scores), end(scores)), end(scores));
cin >> m;
int curr = scores.size()-1;
while (m--)
{
	cin >> score;
	auto rank = 0;
	
	while (curr >= 0 && score >= scores[curr]) 
		curr--;
	
	if (curr == -1) 
		rank = 1;
	else if (score == scores[curr]) 
		rank = curr+1;
	else if (score < scores[curr]) 
		rank = curr+2;
	
	cout << rank << "\n";
}
Posted by: Guest on May-01-2021

Code answers related to "climbing the leaderboard"

Browse Popular Code Answers by Language