Cod sursa(job #952110)

Utilizator dpopovicDana Popovici dpopovic Data 22 mai 2013 18:43:49
Problema Text Scor 100
Compilator c Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>


int main(int argc, char *argv[]) {
	
	int cuv=0, litere=0, this=0, prev=0;
	char c;
	
//	clock_t start = clock();

	FILE *f1 = fopen("text.in", "r");

	while(fscanf(f1, "%c", &c) > 0) {
		if( (c>='a' && c<='z') || (c>='A' && c<='Z') ) {
			this = 1;
			litere++;
		} else {
			this = 0;
		}
		//printf("c=%c,  this=%d  prev=%d  litere=%d   cuv = %d\n", c, this, prev, litere, cuv);
		if(this && !prev)
			cuv++;
		prev = this;
	}
	
	FILE *f2 = fopen("text.out", "w");
	fprintf(f2, "%d\n", litere/cuv);

	fclose(f1);	
	fclose(f2);
	return 0;
}