Pagini recente » Cod sursa (job #2496847) | Cod sursa (job #650354) | Cod sursa (job #2884811) | Cod sursa (job #2850004) | Cod sursa (job #1816811)
#include <fstream>
#include <string>
using namespace std;
ifstream f{ "text.in" };
ofstream q{ "text.out" };
int main()
{
int words = 0;
int len = 0;
bool ok = false;
string s;
while (getline(f, s)) {
ok = false;
int size = s.size();
for (int i = 0; i < size; ++i)
{
if ((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z'))
{
if (!ok) ok = true;
len++;
}
else
{
if (ok) words++;
ok = false;
}
}
if (ok) words++;
}
if (words == 0) words = 1;
q << len / words;
f.close();
q.close();
return 0;
}