Pagini recente » Cod sursa (job #1447941) | Cod sursa (job #1699821) | Cod sursa (job #192915) | Cod sursa (job #2609112)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int len_words, no_words;
char text[1000100];
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;
}