fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const long long MOD=1e9+7;
  4. int lonthunhi(vector<int> &a) {
  5. int n=a.size();
  6. int lon1=-1,lon2=-1;
  7. //Tên biến ko phải thứ bạn đang nghĩ đâu hihi!
  8. //Tìm biến lớn nhất!
  9. for (int i=0;i<n;i++) {
  10. if (a[i]>lon1)
  11. lon1=a[i];
  12. }
  13. // Tìm số lớn thứ hai!
  14. for (int i=0;i<n; i++) {
  15. // Cập nhật liên tục
  16. if (a[i]>lon2 && a[i]!=lon1) {
  17. lon2=a[i];
  18. }
  19. }
  20. return lon2;
  21. }
  22.  
  23. int main() {
  24. vector<int> a = {36,67,69};
  25. cout << lonthunhi(a);
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
67