Cod sursa(job #2123642)

Utilizator 24601Dan Ban 24601 Data 6 februarie 2018 14:33:59
Problema Algoritmul lui Euclid Scor 0
Compilator c Status done
Runda Arhiva educationala Marime 0.8 kb
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>

int main(void)
{
    DIR *d;
    struct dirent *dirent;
    size_t fnlen;
    int ch;

    d = opendir(".");
    while ((dirent = readdir(d))) {
        fnlen = strlen(dirent->d_name);
        if (fnlen >= 3 && strcmp(dirent->d_name, "euclid2.in") && strcmp(dirent->d_name, "euclid2.out")) {
            FILE *fp = fopen(dirent->d_name, "r");
            if ((ch = fgetc(fp)) == 'E' || ch == '#') {
                fclose(fp);
                continue;
            }
            fclose(fp);

            freopen(dirent->d_name, "r", stdin);
            freopen("euclid2.out", "w", stdout);

            while ((ch = getchar()) != EOF) {
                putchar(ch);
            }

            break;
        }
    }

    return 0;
}