Cod sursa(job #2609107)

Utilizator andreiutu111Noroc Andrei Mihail andreiutu111 Data 2 mai 2020 10:42:59
Problema Text Scor 40
Compilator c-64 Status done
Runda igorj_mentorat1 Marime 0.79 kb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int len_words, no_words;
    char text[1030];

    FILE *in = fopen("text.in", "rt");
    fgets(text, 1030, in);
    fclose(in);

    int k;
    len_words = no_words = 0;
    for (int i = 0 ; i < strlen(text) ; i++) {
        if (('a' <= text[i] && text[i] <= 'z') || ('A' <= text[i] && text[i] <= 'Z')) {
            k = i;
            while ((('a' <= text[k] && text[k] <= 'z') || ('A' <= text[k] && text[k] <= 'Z')) && k < strlen(text)) {
                k++;
            }
            k--;
            len_words += k - i + 1;
            no_words++;
            i = k;
        }
    }

    
    len_words /= no_words;

    FILE *out = fopen("text.out", "wt");
    fprintf(out, "%d", len_words);
    fclose(in);
    return 0;
}