Cod sursa(job #909265)

Utilizator rauca_bogdanRauca Bogdan Adrian rauca_bogdan Data 10 martie 2013 15:02:07
Problema Text Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <fstream>
#include <string.h>
using namespace std;

ifstream is("text.in");
ofstream os("text.out");

int main()
{
    char a[1000000];
    int lungime;
    long long cuvinte = 0;
    long long litere = 0;


    while( is >> a )
    {
       lungime = strlen(a);
       bool esteCuvant = false;
       int nrLitere = 0;
       for( int i = 0; i < lungime; ++i )
       {
              if( (a[i] >= 'a' && a[i] <= 'z') || (a[i] >= 'A' && a[i] <= 'Z')  )
              {
                     esteCuvant = true;
                     nrLitere++;
              }

              if( a[i] == '-' && nrLitere != 0 && i < lungime - 1 && ( (a[i+1] >= 'a' && a[i+1] <= 'z') || (a[i+1] >= 'A' && a[i+1] <= 'Z') )  )
                     cuvinte++;
       }

       if( esteCuvant )
       {
              cuvinte++;
              litere += nrLitere;
       }
    }

    os << litere / cuvinte;

    os.close();
    is.close();
    return 0;
}