-
Notifications
You must be signed in to change notification settings - Fork 0
/
Climbing_the_Leaderboard.cpp
75 lines (63 loc) · 1.51 KB
/
Climbing_the_Leaderboard.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* Title : Climbing_the_Leaderboard.cpp
* Author : Tridib Samanta
* Created : 18-01-2020
* Link : https://www.hackerrank.com/challenges/climbing-the-leaderboard/problem
**/
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <map>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int removeDuplicates(int arr[], int n);
int main() {
//Leaderboard
int n;
cin>>n;
int scores[n];
for(int i=0;i<n;i++) {
cin>>scores[i];
}
int sof=sizeof(scores)/sizeof(scores[0]);
sof=removeDuplicates(scores,sof);
/*for(int i=0;i<sof;i++) {
cout<<scores[i];
}*/
//Alice's Part
int i=sof-1,m,tmp;
cin>>m;
for(int j=0;j<m;j++) {
cin>>tmp;
if(tmp<scores[sof-1])
cout<<sof+1<<endl;
else if(tmp>scores[0] || tmp==scores[0])
cout<<"1"<<endl;
else {
while(i>0) {
if(tmp==scores[i]) {
cout<<i+1<<endl;
break;}
if(tmp>scores[i] && tmp<scores[i-1]) {
cout<<i+1<<endl;
break; }
i--;
}
}
}
return 0;
}
int removeDuplicates(int arr[], int n) {
if (n==0 || n==1)
return n;
int j = 0;
for (int i=0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j++] = arr[i];
arr[j++] = arr[n-1];
return j;
}