AlenAntonelli

Libros_Alen

May 12th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. ///Trello, Principiante, Libros
  2. #include <iostream> /// AlenAntonelli
  3. #include <vector>
  4. using namespace std;
  5. long Resta (long a, long b);
  6. int main ()
  7. {
  8.     int N=0, s=0, emp, ter;
  9.     long sum=0, men=0, aux;
  10.     cin >> N;
  11.     vector <long> v (N, 0);
  12.     for (int i=0; i<N; i++)
  13.     {
  14.         cin >> aux;
  15.         v[i]=aux;
  16.     }
  17.     for (int i=1; i<N-1; i++)
  18.     {
  19.         sum=0;
  20.         for (int j=0; j<N-1; j++)
  21.         {
  22.             if (j!=i)
  23.             {
  24.                 emp=0;
  25.                 ter=0;
  26.                 if (j==i-1)
  27.                 {
  28.                     emp=j;
  29.                     ter=j+2;
  30.                 }
  31.                 else
  32.                 {
  33.                     emp=j;
  34.                     ter=j+1;
  35.                 }
  36.                 sum=sum+Resta(v[emp],v[ter]);
  37.             }
  38.  
  39.         }
  40.         if (i==1 || (men > sum) )
  41.         {
  42.             men=sum;
  43.             s=i+1;
  44.         }
  45.     }
  46.  
  47.     cout << s << " ";
  48.     return s;
  49. }
  50.  
  51. long Resta (long a, long b)
  52. {
  53.     int resultado = a - b;
  54.     if (resultado < 0)
  55.         resultado = resultado * (-1);
  56.     return resultado;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment