Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Trello, Principiante, Libros
- #include <iostream> /// AlenAntonelli
- #include <vector>
- using namespace std;
- long Resta (long a, long b);
- int main ()
- {
- int N=0, s=0, emp, ter;
- long sum=0, men=0, aux;
- cin >> N;
- vector <long> v (N, 0);
- for (int i=0; i<N; i++)
- {
- cin >> aux;
- v[i]=aux;
- }
- for (int i=1; i<N-1; i++)
- {
- sum=0;
- for (int j=0; j<N-1; j++)
- {
- if (j!=i)
- {
- emp=0;
- ter=0;
- if (j==i-1)
- {
- emp=j;
- ter=j+2;
- }
- else
- {
- emp=j;
- ter=j+1;
- }
- sum=sum+Resta(v[emp],v[ter]);
- }
- }
- if (i==1 || (men > sum) )
- {
- men=sum;
- s=i+1;
- }
- }
- cout << s << " ";
- return s;
- }
- long Resta (long a, long b)
- {
- int resultado = a - b;
- if (resultado < 0)
- resultado = resultado * (-1);
- return resultado;
- }
Advertisement
Add Comment
Please, Sign In to add comment