Cod sursa(job #1472942)

Utilizator VadaVadastreanu Cristian Vada Data 18 august 2015 10:26:03
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>
using namespace std;

int main()
{	
	FILE *f, *g;
	f = fopen("text.in","r");
	g = fopen("text.out","w");

	char c;

	int cuvinte = 0;
	int state = 0;
	int litere = 0;
	while (fscanf(f,"%c",&c) != EOF){
		if ((('a' <= c && c <= 'z') || ( 'A' <= c && c <= 'Z' )) && state == 0)
			state = 1;
		else if ((('a' <= c && c <= 'z') || ( 'A' <= c && c <= 'Z' )) && state == 1)
			state = 2;
		else if (!(('a' <= c && c <= 'z') || ( 'A' <= c && c <= 'Z' )) && (state == 2 || state == 1))
			state = 0;

		if (state == 1){
			cuvinte++;
			litere++;
		
		}else if (state == 2){
			litere++;
		}else if (state == 0) {
			continue;
		}
		
	}
	fprintf(g,"%d %d %d",litere/cuvinte, litere , cuvinte);
	
	

	fclose(f);
	fclose(g);


}