Cod sursa(job #2911506)

Utilizator aminaAmina Suciu amina Data 30 iunie 2022 11:01:37
Problema Text Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <iostream>
#include<cstdio>

using namespace std;
const int Nmax=1000000;
int is_letter(char c) {
    if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')) {
        return 1;
    }
    return 0;
}

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



freopen("text.out", "w", stdout);

  char ch;
  int wordlength=0;
  int nrletter=0;
  int nrwords=0;
  while(!feof(fin))
  {
      fscanf(fin, "%c", &ch);
      if(feof(fin))break;
      if(is_letter(ch)){wordlength++;
      }
       else {
        if(wordlength!=0){
            nrwords++;
            nrletter+=wordlength;
            wordlength=0;

        }

       }
  }
cout<<nrletter/nrwords;
}