Cod sursa(job #1816811)

Utilizator M.AndreiMuntea Andrei Marius M.Andrei Data 26 noiembrie 2016 22:22:21
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>
#include <string>
using namespace std;

ifstream f{ "text.in" };
ofstream q{ "text.out" };

int main()
{

   int words = 0;
   int len = 0;
   bool ok = false;
   string s;

   while (getline(f, s)) {
      ok = false;
      int size = s.size();

      for (int i = 0; i < size; ++i)
      {
         if ((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z'))
         {
            if (!ok) ok = true;
            len++;
         }
         else
         {
            if (ok) words++;
            ok = false;
         }
      }
      if (ok) words++;
   }
   if (words == 0) words = 1;
   q << len / words;

   f.close();
   q.close();
   return 0;
}