Cod sursa(job #20358)

Utilizator costinbCostin Boldisor costinb Data 21 februarie 2007 11:35:08
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <stdio.h>
#include <cctype>
using namespace std;

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

	  long long totalchars = 0;
	  long long nrcuv = 0;

	  char c;
	  char state = 'n';

	  
	  while(fscanf(f,"%c",&c) != EOF){
		  if(isalpha(c))
			  ++totalchars;

		  switch(state){
			  case 'n':
				  if(isalpha(c)){
					  state = 'c';
					  ++nrcuv;					  
				  }
				  break;
			  case 'c':
				  if(!isalpha(c)){
					  state = 'n';
				  }				  

		  }
	  }
	  fclose(f);

	  f = fopen("text.out","w");
	  fprintf(f,"%d",(totalchars / nrcuv));
	  fclose(f);
}