-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort.cpp
51 lines (39 loc) · 1.01 KB
/
sort.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
/* Universidade de Brasília
* Departamento de Ciência da Computação
* CIC0169 - Programação Competitiva
* Prof. Dr. Vinicius R. P. Borges
*
* Tópico: Fundamentos de C/C++
* Esse código-fonte apresenta operacoes de busca sequencial e binaria (lower bound e upper bound) em vetores
*
* Compilar no terminal:
* $ g++ sort.cpp -std=c++17 -o ordena
* Executar:
* $ ./ordena
*/
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
bool comparaPares(pii a, pii b){
if(a.second < b.second)
return true;
return false;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,aux,ans;
vector<int> v;
vector<pii> vpairs;
cin >> n;
for(int i = 0; i < n; i++){
cin >> aux;
v.push_back(aux);
vpairs.push_back(make_pair(aux,i));
}
sort(v.begin(),v.end());
// ordena em relacao ao elemento second do pair
sort(vpairs.begin(),vpairs.end(),comparaPares);
return 0;
}