- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C++ code to find position of students after coding contest

Suppose we have an array A with n elements. In a coding contest, in total n students will participate, and before the start, every one of them has some positive rating (integer). A[i] represents the rating of ith student. After the contest ends, every student will end up with some positive integer position. We are expecting the students will take places according to their ratings. If student A has rating strictly lower than student B, A will get strictly greater position than B. We have to find the position at the end of the contest.

So, if the input is like A = [3, 5, 3, 4, 5], then the output will be [4, 1, 4, 3, 1] because 2nd and 5th students share the first position with highest rating, 4th student is next with third position, 1st and 3rd students are the last sharing fourth position.

## Steps

To solve this, we will follow these steps −

n := size of A for initialize i := 0, when i < n, update (increase i by 1), do: d := 1 for initialize j := 0, when j < n, update (increase j by 1), do: if A[j] > A[i], then: (increase d by 1) cout << d << ", "

## Example

Let us see the following implementation to get better understanding −

#include <bits/stdc++.h> using namespace std; void solve(vector<int> A){ int n = A.size(); for (int i = 0; i < n; i++){ int d = 1; for (int j = 0; j < n; j++){ if (A[j] > A[i]) d++; } cout << d << ", "; } } int main(){ vector<int> A = { 3, 5, 3, 4, 5 }; solve(A); }

## Input

{ 3, 5, 3, 4, 5 }

## Output

4, 1, 4, 3, 1,

- Related Questions & Answers
- C++ code to find winner of math contest
- C++ code to find different winner and non-winner counts on a contest
- C++ code to find minimum k to get more votes from students
- C++ code to find minimal tiredness after meeting
- C++ program to find maximum distance between two rival students after x swaps
- C++ code to find minimum stones after all operations
- C++ code to find xth element after removing numbers
- C++ code to find tree height after n days
- C++ code to find money after buying and selling shares
- C++ code to find corrected text after double vowel removal
- Program to find out the position of a ball after n reversals in Python
- C++ code to find final number after min max removal game
- Position of robot after given movements in C++
- Huffman Coding
- C++ code to get minimum sum of cards after discarding