Advertisement
2000fer

Untitled

Apr 26th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <stdlib.h>
  4. #define INF (1 << 30)
  5.  
  6.  
  7. using namespace std;
  8.  
  9. int main(){
  10.  
  11.  
  12.  
  13. int n,a,diferencia=0,pos,menor,posMenor=0;
  14. vector <int> alturas;
  15. vector <int> prueba;
  16.  
  17. cin >> n;
  18. cout <<endl;
  19. for(int i=0;i<n;i++){ //Cargo las alturas
  20. cin >> a;
  21. alturas.push_back(a);}
  22.  
  23.  
  24. menor = INF;
  25. for(int i=1;i<n-1;i++){
  26. for(int j=0;j<n;j++){ //Carga las alturas sin un libro
  27. if(j!=i){
  28. a = alturas[j];
  29. prueba.push_back(a);}}
  30.  
  31.  
  32. for(int k=0;k<n-2;k++){
  33. diferencia+= abs(prueba[k]-prueba[k+1]);}
  34. if(diferencia <= menor){
  35. menor = diferencia;
  36. posMenor = i;}
  37.  
  38. prueba.erase(prueba.begin(),prueba.end());
  39. diferencia = 0;
  40. }
  41.  
  42. cout <<posMenor+1;
  43.  
  44.  
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement