Cod sursa(job #1266575)

Utilizator TheBos5Alexandru Iercosan TheBos5 Data 18 noiembrie 2014 21:38:34
Problema Text Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
// Fact.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdlib.h>
#include <time.h>



int main()
{
	int i = 0;
	int j = 0;
	bool AreLitere = false;
	int charcnt = 0;
	int wordcnt = 0;
	char *string = NULL;
	FILE *TextIn = NULL;
	FILE *TextOut = NULL;
	string = (char*)malloc(1024 * 1024 + 1);				//(string[i] <= 'a' && string[i] >= 'z') || (string[i] <= 'A' && string[i] >= 'Z')
	TextIn = fopen("text.in", "r");							//Conditie Litera
	if (TextIn == NULL) {
		printf("Eroare deschidere fisier intrare");
		return 0;
	}
	TextOut = fopen("text.out", "w");
	fgets(string , 1024 * 1024 + 1, TextIn);
	while (string[i] != 0) {
		if ((string[i] >= 'a' && string[i] <= 'z') || (string[i] >= 'A' && string[i] <= 'Z')) {
			charcnt++;
		}
		i++;
	}
	while (j < i) {
		AreLitere = 0;
		while (((string[j] >= 'a' && string[j] <= 'z') || (string[j] >= 'A' && string[j] <= 'Z')) && j < i) {
			j++;
			AreLitere = 1;
		}
		while (!((string[j] >= 'a' && string[j] <= 'z') || (string[j] >= 'A' && string[j] <= 'Z')) && j < i) {
			j++;
		}
		if ( AreLitere ) {
			wordcnt++;
		}
	}
	fprintf(TextOut, "%ld", charcnt / wordcnt);
	free(string);
	return 0;
}