How to end this program with EOF?

Asked

Viewed 930 times

1

I was solving a Urionlinejudge site problem and it was asked for the input to end with EOF. I made the code perfectly, except that I don’t know how to implement the EOF. How can I do it?

#include <stdio.h>

int main(void){
    int N, Q, i, e[101], o[101], d, j, m = -1, n;
    scanf("%d %d", &N, &Q);

    for(i=0;i<101;i++){
        e[i] = 0;
        o[i] = 0;
    }


    for(i = 1;i<=N;i++){
        scanf("%d", &e[i]);
    }
    for(i = 1;i<=N;i++){
        for(j=1;j<=N;j++){
            if (e[j]>m){
                m=e[j];
                n = j;
            }
        }
        o[i]=m;
        e[n]=-2;
        m = -1;
    }
    for(i = 1;i<=Q;i++){
        scanf("%d", &d);
        printf("%d\n", o[d]);
    }
    return 0;
}

1 answer

2


After reading the first line (two integers) you use the EOF within a while to read the n entries:

int entrada;    
while(scanf("%d", &entrada) != EOF) {
    // ...
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.