Cod sursa(job #2443655)

Utilizator EdyOnuEdy Onu EdyOnu Data 28 iulie 2019 22:56:45
Problema Text Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
// 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 lengthWords / nrWords;
	}

private:

	void __readData(istream& in) {
		getline(in, line);
	}

	string line;
};

int main()
{
	ofstream{"text.out"} << Solver{ ifstream{"text.in"} }.result();
}