Pagini recente » Cod sursa (job #2844715) | Cod sursa (job #1700624) | Cod sursa (job #1439484) | Cod sursa (job #2863842) | Cod sursa (job #974390)
Cod sursa(job #974390)
#include <fstream>
#include <iostream>
#include <cstring>
#include <iterator>
#include <algorithm>
#define MAX_SIZE (1024 * 1024 * 1024 + 1)
using namespace std;
char text[MAX_SIZE];
int main()
{
fstream fin("text.in", fstream::in);
fstream fout("text.out", fstream::out);
fin.seekg (0, fin.end);
int length = fin.tellg();
fin.seekg (0, fin.beg);
fin.read(text, length);
//cout << text << endl;
int numWords = 0;
int wordsLength = 0;
int currentWordLength = 0;
for (int i=0; i<length; ++i)
{
if (isalpha(text[i]))
{
currentWordLength++;
}
else
{
if (currentWordLength > 0)
{
numWords++;
wordsLength += currentWordLength;
}
currentWordLength = 0;
}
}
//cout << numWords << " " << wordsLength << endl;
fout << wordsLength / numWords << "\n";
return 0;
}