fork download
  1. /*
  2. Task: Problem 6.07
  3. Date: Dec 24, 2020
  4. Author: aLittleLove (Minh Vu)
  5. */
  6.  
  7. #include<bits/stdc++.h>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  14. //freopen("input.txt","r",stdin);
  15. int n; cin >> n;
  16. set<int> s;
  17. for (int i=1; i<=n; i++)
  18. {
  19. int x; cin >> x;
  20. s.insert(x);
  21. }
  22. if (s.size()<2) cout << 0; // it hon 2 phan tu -> ko co phan thu lon thu 2
  23. else
  24. {
  25. set<int>::reverse_iterator it = s.rbegin(); //phan tu o cuoi s (phan tu lon nhat)
  26. it++; //di nguoc lai den phan tu lon thu 2
  27. cout << *it;
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0s 5012KB
stdin
8
2 9 5 6 9 8 9 1
stdout
8