fork(1) download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <numeric>
  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) &&
  12. (std::distance(t, std::unique(t, t + n)) == n) &&
  13. (std::accumulate(t, t + n, 0) == (n * (n + 1)) / 2);
  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 3468KB
stdin
Standard input is empty
stdout
1