Cod sursa(job #1817396)

Utilizator specialkhouseTodireanu Constantin Catalin specialkhouse Data 27 noiembrie 2016 19:00:12
Problema Text Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <stdio.h>
#include <stdlib.h>

int esteCaracter(char ch);

int main()
{
	char ch = 0;
	long int nr_caractere = 0;
	long int nr_cuvinte = 0;
	bool k = false;

	freopen("test.in", "r", stdin);
	freopen("test.out", "w", stdout);

	while ((ch = fgetc(stdin)) != EOF) {
		if (esteCaracter(ch) == 1) {
			nr_caractere++;
			if (!k) {
				nr_cuvinte++;
			}
			k = true;
		}
		else {
			k = false;
		}
	}

	fprintf(stdout, "%d \n", nr_caractere / nr_cuvinte);

	return 0;
}

int esteCaracter(char ch)
{
	int rez = 0;

	if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) {
		rez = 1;
	}

	return rez;
}