Cod sursa(job #383546)

Utilizator ionutz32Ilie Ionut ionutz32 Data 16 ianuarie 2010 20:37:15
Problema Text Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <stdio.h>
#include <iostream>
int fileLen,n,begin,sum,nrc,poz;
char *s,*pa;
bool k;
int main()
{
	FILE *fp; 
	fp=fopen("text.in","rb");
	fseek(fp, 0, SEEK_END);
	fileLen=ftell(fp);
	fseek(fp, 0, SEEK_SET);
	s=(char *)malloc(fileLen+1); 
	fread(s,fileLen,1,fp);
	fclose(fp);
	pa=s; 
	freopen("text.out","w",stdout);
	n=fileLen;
	while (n--)
	{
		if ((*pa>='a' && *pa<='z') || (*pa>='A' && *pa<='Z'))
		{
			if (!k)
				poz=n;
			k=true;
		}
		else
			if (k)
			{
				k=false;
				sum+=poz-n;
				nrc++;
			}
		pa++;
	}
	if (k)
	{
		sum+=poz;
		nrc++;
	}
	printf("%d",int(sum/nrc));
	return 0;
}