Cod sursa(job #3301462)

Utilizator tavy_codingAlbuica Ioan Octavian tavy_coding Data 26 iunie 2025 17:14:37
Problema Text Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

using namespace std;

int main()
{
    FILE *file_in = fopen("text.in", "r");
    FILE *file_out = fopen("text.out", "w");
    
    fseek(file_in, 0, SEEK_END);
    long sz = ftell(file_in);
    fseek(file_in, 0, SEEK_SET);

    char *buf = (char *)malloc(sz + 1);
    fread(buf, 1, sz, file_in);
    buf[sz] = '\0';

    for (long i = 0; i < sz; i++) {
        if (!isalpha((unsigned char)buf[i])) {
            buf[i] = ' ';
        }
    }

    int l = 0, nr = 0;
    char *s = strtok(buf, " ");
    while (s) {
        l += strlen(s);
        nr++;
        s = strtok(NULL, " ");
    }

    fprintf(file_out, "%d\n", l / nr);
    fclose(file_in);
    fclose(file_out);
}