fork download
  1. #include <bits/stdc++.h>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int N,i,j,flag;
  9. cin>>N; // No. of elements in the array
  10.  
  11. int A[N+1];
  12. flag=1; // Flag initialization
  13.  
  14. for(i=0;i<N;i++) // Input
  15. cin>>A[i];
  16.  
  17. sort(A,A+N); // Sorting the Array
  18.  
  19. for(i=N-2;i>=0;i--)
  20. {
  21. if(A[i]!=A[i+1])
  22. {
  23. cout<<A[i]<<endl; // Answer
  24. flag=0; // We have encountered the second maximum unique element.
  25. break;
  26. }
  27. }
  28. if(flag) // Flag will be 1 if all the elemts which is the special case here.
  29. cout<<0<<endl;
  30.  
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
0