Cod sursa(job #1312880)

Utilizator savigunFeleaga Dragos-George savigun Data 10 ianuarie 2015 01:00:52
Problema Text Scor 50
Compilator c Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
	FILE *f, *g;
	if((f=fopen("text.in", "rt"))==NULL)
		return -1;
	if((g=fopen("text.out", "wt"))==NULL)
		return -1;
	int l, i, c=0, p=0, o=0;
	char *s;
	fseek(f, 0, SEEK_END);
	l=ftell(f);
	fseek(f, 0,0);
	s=malloc((l-2)*sizeof(char));
	fread(s,sizeof(char),l,f);
	for(i=1;i<l;i++)
		if((*(s+i)<'a' ||  *(s+i)>'z') && (*(s+i)<'A' ||  *(s+i)>'Z'))
			if((*(s+i-1)>='a' &&  *(s+i-1)<='z') || (*(s+i-1)>='A' &&  *(s+i-1)<='Z'))
				{
					c++;
					p++;
				}
			else
				p++;
	l--;
	if(c)	
		o=(l-p)/c;
	fprintf(g,"%d",o);
	free(s);
	fclose(f);
	fclose(g);
	return 0;
}