Cod sursa(job #1816810)

Utilizator M.AndreiMuntea Andrei Marius M.Andrei Data 26 noiembrie 2016 22:18:49
Problema Text Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 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;

   getline(f, s);
   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;
}