-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
45 lines (33 loc) · 800 Bytes
/
main.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
#include <iostream>
using namespace std;
void ordenar_desc(int v[], int tam);
int main(){
int n, q;
while(cin >> n >> q){
int notas[n], pos[q];
for(int i = 0; i < n; i++)
cin >> notas[i];
for(int i = 0; i < q; i++)
cin >> pos[i];
ordenar_desc(notas, n);
for(int i = 0; i < q; i++)
cout << notas[pos[i] - 1] << endl;
}
return 0;
}
// Bubble sort
void ordenar_desc(int v[], int tam){
int i, temp;
bool trocou;
do{
trocou = false;
for(i = 0; i < tam - 1; i++){
if(v[i] < v[i + 1]){
temp = v[i];
v[i] = v[i + 1];
v[i + 1] = temp;
trocou = true;
}
}
}while(trocou);
}