fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <set>
  4. using namespace std;
  5.  
  6. bool g(int *t, int n)
  7. {
  8. if ( n == 0 )
  9. return false;
  10. std::sort(t, t + n);
  11. return (t[0] == 1) && // first number must be 1
  12. (t[n-1] == n) && // last must be n
  13. (std::set<int>(t, t+n).size() == n); // all must be unique
  14. }
  15.  
  16. int main()
  17. {
  18. int arr[] = {1,2,3,4,5,6,7};
  19. std::cout << g(arr, 7);
  20. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
1