Advertisement
wym1111

Untitled

Oct 6th, 2023
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. a[n]
  2.  
  3. int maxa1 = -1, maxa2 = -1;
  4. int pos1 = 0, pos2 = -1;
  5.  
  6. for (int i = 1; i <= n; i ++) {
  7.     if (a[i] > maxa1) {
  8.         maxa2 = maxa1;
  9.         maxa1 = a[i];
  10.         pos2 = pos1;
  11.         pos1 = i;
  12.     } else if (a[i] > maxa2) {
  13.         maxa2 = a[i];
  14.         pos2 = i;
  15.     }
  16. }
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement