Cod sursa(job #2005863)

Utilizator PetrescuAlexandru Petrescu Petrescu Data 28 iulie 2017 13:28:31
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <stdio.h>
#include <iostream>
#include <stdlib.h>

using namespace std;
int main()
{
  FILE *fin, *fout;
  char c;
  int semafor = 0, lungime = 0, sum = 0, nrc = 0;

  fin = fopen("text.in", "r");
  fout = fopen("text.out", "w");
  c = fgetc( fin );
  while(c != EOF)
  {
    if((('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z')) && (semafor == 0))
    {
      semafor = 1;
      lungime++;
      nrc++;
    }
    else if(('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'))lungime++;
    else if(semafor == 1)
    {
      semafor = 0;
      sum += lungime;
      lungime = 0;
    }
    c = fgetc( fin );
  }
  if(nrc == 0)fprintf(fout, "0");
  else fprintf(fout, "%d", sum / nrc);
  fclose( fin );
  fclose( fout );
  return 0;
}