Cod sursa(job #2429910)

Utilizator andrei885Andrei Paul Vintila andrei885 Data 11 iunie 2019 20:27:24
Problema Text Scor 30
Compilator c-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void main() {
  size_t text_size = 1048577;
  char *text = (char *) malloc(sizeof(char) * text_size);
  FILE *fp = fopen("text.in", "r");
  getline(&text, &text_size, fp);
  fclose(fp);

  char delims[44] = " ,.;\':\"?!/[]{}<>`~@#$%^&*()-_=+\\|0123456789\0";
  char *word = strtok(text, delims);
  int no_of_words = 0;
  int total_length = 0;
  while (word) {
    total_length += strlen(word);
    no_of_words++;
    word = strtok(NULL, delims);
  }

  int res = total_length / no_of_words;

  fp = fopen("text.out", "w");
  fprintf(fp, "%d", res);
  fclose(fp);
}