Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
433 B
3
Indexable
Never
#include<stdio.h>

int main()
{
   int max=-1;
   int max2=-1;
   int in,n;
   scanf("%d", &n);

   for(int i=0; i<n; i++) {
      scanf("%d", &in);
      if(in>max) {
         max2 = max;
         max = in;
      }
      else if(in>max2) {
         max2 = in;
      }
      if(i==0) 
         printf("0 ");
      else if(i!=n-1)
         printf("%d ", max2);
      else
         printf("%d\n", max2);
   }
}