Saturday, 15 July 2017

c++ - What's wrong with my code about find the max one and the min one by vector

I wrote a code,it will find the max one and min one in an arr by vector
but I simply don't know what I've made an error.




Every time I try it return zero for me.lol



#include
#include
#include
using namespace std;
int main()
{
int a[999];
int n;

cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector arr(a[1], a[n]);
int max = *max_element(arr.begin(), arr.end());
int min = *min_element(arr.begin(), arr.end());
int dis = max - min; cout << dis << endl;
return 0;
}

No comments:

Post a Comment

casting - Why wasn&#39;t Tobey Maguire in The Amazing Spider-Man? - Movies &amp; TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...