Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <stdlib.h>
- #define INF (1 << 30)
- using namespace std;
- int main(){
- int n,a,diferencia=0,pos,menor,posMenor=0;
- vector <int> alturas;
- vector <int> prueba;
- cin >> n;
- cout <<endl;
- for(int i=0;i<n;i++){ //Cargo las alturas
- cin >> a;
- alturas.push_back(a);}
- menor = INF;
- for(int i=1;i<n-1;i++){
- for(int j=0;j<n;j++){ //Carga las alturas sin un libro
- if(j!=i){
- a = alturas[j];
- prueba.push_back(a);}}
- for(int k=0;k<n-2;k++){
- diferencia+= abs(prueba[k]-prueba[k+1]);}
- if(diferencia <= menor){
- menor = diferencia;
- posMenor = i;}
- prueba.erase(prueba.begin(),prueba.end());
- diferencia = 0;
- }
- cout <<posMenor+1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement