Pagini recente » Cod sursa (job #45836) | Cod sursa (job #567842) | Cod sursa (job #940936) | Cod sursa (job #404260) | Cod sursa (job #390584)
Cod sursa(job #390584)
#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(fscanf(f, "%c", &c)!= EOF)
{
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;
}