Cod sursa(job #3827)

Utilizator MihaiT_testTabara Mihai Test MihaiT_test Data 29 decembrie 2006 03:30:37
Problema Text Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.48 kb
#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 int 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() && fin.peek() != '\n' )
    {
            if ( fin.peek() == ' ' ) 
            {
                 fin.get();
                 s += ' ';
            }
            else
            {
                fin >> ch;
                s += ch;
            }
    }
    //fout << s << "\n";
    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 mihai;
    mihai.str( prov );
    string ss;
    while ( mihai >> ss )
    {
            sol.push_back( ss );
    }
    for ( j = 0 ;j < sol.size(); ++j )
    {
            lungime += sol[j].size();//fout << sol[j] << " ";
            nrc++;
    }
    //fout << lungime << " " << nrc << "\n";
    ok = (int)(lungime/nrc);
    fout << ok << "\n";
    fin.close();
    fout.close();
    
    return 0;
}