Pagini recente » Cod sursa (job #2573117) | Cod sursa (job #2661505) | Cod sursa (job #1814007) | Cod sursa (job #1274607) | Cod sursa (job #2444636)
// text.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include "pch.h"
#include <iostream>
#include <regex>
#include <fstream>
#include <string>
using namespace std;
class Solver {
public:
explicit Solver(istream&& in) {
__readData(in);
}
int result() {
regex e{ "([a-zA-Z]+)" };
smatch match;
int nrWords = 0, lengthWords = 0;
for (; regex_search(line, match, e); line = match.suffix()) {
++nrWords;
lengthWords += match[0].length();
}
return nrWords ? lengthWords / nrWords : 0;
}
private:
void __readData(istream& in) {
string _line;
while (!in.eof()) {
getline(in, _line);
line = line + '\n' + _line;
};
}
string line;
};
int main()
{
ofstream{ "text.out" } << Solver{ ifstream{"text.in"} }.result();
}