Cod sursa(job #293386)
#include <cstdio>
bool litera(char c)
{
if (c >= 'a' && c <='z')
return 1;
if (c >= 'A' && c <= 'Z')
return 1;
return 0;
}
int main()
{
FILE *f = fopen("text.in", "r");
char c;
long Ltotal = 0, nr_cuv = 0, poz_init, i = 0;
bool cuvant = false;
while(!feof(f))
{
fscanf(f, "%c", &c);
i++;
if ((litera(c)) && cuvant == false)
{
cuvant = true;
poz_init = i;
}
if (!(litera(c)) && cuvant == true)
{
Ltotal += i - poz_init;
nr_cuv++;
cuvant = false;
}
}
fclose(f);
f = fopen("text.out", "w");
if (nr_cuv != 0)
fprintf(f, "%ld", Ltotal / nr_cuv);
else
fprintf(f, "0\n");
fclose(f);
return 0;
}