Cod sursa(job #3830)

Utilizator TabaraTabara Mihai Tabara Data 29 decembrie 2006 03:50:39
Problema Text Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.37 kb
//60 puncte
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <iostream>
#include <map>
#include <sstream>
using namespace std;

#define in "text.in"
#define out "text.out"

typedef long long LI;
string s, rez, prov;
char ch;
vector<string> sol;
LI lungime, nrc, ok;

int main()
{
    ifstream fin ( in );
    ofstream fout ( out );
    LI i, j;
    while ( !fin.eof() )
    {
            if ( fin.peek() == ' ' ) 
            {
                 fin.get();
                 s += ' ';
            }
            else
            {
                fin >> ch;
                s += ch;
            }
    }
    rez = "";
    prov = "";

    for ( i = 0; i < s.size(); ++i )
    {
          if ( isalpha( s[i] ) || s[i] == ' ' || s[i] == '-' ) rez += s[i];
    } 
    //fout << rez << "\n";
    
    for ( i = 0; i < rez.size(); ++i )
    {
          if ( rez[i] == '-' ) prov += ' ';
          else prov += rez[i];
    }
    //fout << prov << "\n";
    
    istringstream st;
    st.str( prov );
    string ss;
    while ( st >> ss )
    {
            sol.push_back( ss );
    }
    for ( j = 0 ;j < sol.size(); ++j )
    {
            lungime += sol[j].size();
            nrc++;
    }
    
    ok = (int)(lungime/nrc);
    fout << ok << "\n";
    fin.close();
    fout.close();
    
    return 0;
}