Pagini recente » Cod sursa (job #581029) | Cod sursa (job #3222000) | Cod sursa (job #1336778) | Cod sursa (job #2714150) | Cod sursa (job #1725831)
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int trim(string s)
{
int a = 0, words = 0, total = 0;
for (int i = 0; i < s.size(); i++)
{
if ((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z'))
a++;
else
{
if (a > 0)
{
words++;
total+= a;
a = 0;
}
}
}
return total / words;
}
int main()
{
ifstream f("text.in");
ofstream g("text.out");
string line;
string content;
while (getline(f, line) != NULL)
content.append(line);
g<<trim(content);
return 0;
}