Untitled

 avatar
user_1737235546
c_cpp
2 years ago
500 B
1
Indexable
Never
#include <stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int arr[n];
    int max=-1, ans=-1;
    for(int i=0; i<n; i++){
        scanf("%d",&arr[i]);
        if(arr[i]>max){
            ans=max;
            max=arr[i];
        }
        if(arr[i]>ans && arr[i]<max){
            ans=arr[i];
        }
        if(i==0) printf("0 ");
        else if(i!=n-1 && i!=0) printf("%d ",ans);
        else if(i==n-1)printf("%d\n",ans);
        //printf("max=%d, ans=%d\n");
    }
}