Cod sursa(job #262811)

Utilizator ShootMeBistriceanu Andrei ShootMe Data 19 februarie 2009 17:51:36
Problema Text Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <stdio.h>
#include <string.h>



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

	long nbChars = 0;
	long nbWords = 0;
	char c;
	char oldCh = ' ';
	bool lastChIsLetter = false;
	while((c=getc(in))!=EOF) 
	{
		switch (c)
		{
			case ' ':
			case ',':
			case '!':
			case '?':
			case '.':
			case '\n':
			case '-':
			case '+':
			case '/':
			case ':':
			case ';':
			case '(':
			case ')':
			case '[':
			case ']':
			case '{':
			case '}':
			case '|':
			case '<':
			case '>':
			case '=':
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
				lastChIsLetter = false;
				break;
			default:
				nbChars ++;
				if (!lastChIsLetter)
					nbWords ++;
				lastChIsLetter = true;
				break;
		}

		oldCh = c;
	}

	fprintf(out, "%ld", nbChars/nbWords);
	fclose(in);
	fclose(out);
}