fork download
  1. #include<iostream>
  2. #include<algorithm>
  3. using namespace std;
  4. int main()
  5. {
  6. int a[]={2, 3, -7, 6, 8, 1, -10, 15};
  7. int n=sizeof(a)/sizeof(a[0]);
  8. int i,j=1,count=0;
  9. sort(a,a+n);
  10. for(j=0;j<n;++j)
  11. {
  12. if(a[j]<0)
  13. count++;
  14. }
  15. j=1;
  16. i=count;
  17. while(i<n)
  18. {
  19.  
  20. if(a[i]!=j)
  21. {
  22. cout<<j;
  23. break;
  24. }
  25. ++j;
  26. ++i;
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
4