Pagini recente » Cod sursa (job #892284) | Cod sursa (job #1008547) | Cod sursa (job #2473849) | Cod sursa (job #151283) | Cod sursa (job #2444640)
// 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() const {
return nrWords ? lengthWords / nrWords : 0;
}
private:
void __readData(istream& in) {
string _line;
while (getline(in, _line)) {
__result(_line);
};
}
void __result(string& line) {
regex e{ "([a-zA-Z]+)" };
smatch match;
for (; regex_search(line, match, e); line = match.suffix()) {
++nrWords;
lengthWords += match[0].length();
}
}
int nrWords = 0, lengthWords = 0;
};
int main()
{
ofstream{ "text.out" } << Solver{ ifstream{"text.in"} }.result();
}