Cod sursa(job #2761952)

Utilizator bojemoiRadu Mamaliga bojemoi Data 4 iulie 2021 16:00:47
Problema Text Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include<fstream>
#include<iostream>
#include<string>
using namespace std;

ifstream fin("text.in");
ofstream fout("text.out");

bool isLetter(char c){
	int asciiCode = (int)(c);
	return (asciiCode > 64 && asciiCode < 91) || (asciiCode > 96 && asciiCode < 123 );
}

int main(){
	string text;
	long long nrLetters = 0, nrWords = 1;
	int averageLength;
	
	getline(fin,text);	

	for(int i = 0; i<text.length(); ++i){
		if(isLetter(text[i])){
			++nrLetters;
		}
		if((text[i] == ' ' || text[i] == '-') && isLetter(text[i-1])){
			++nrWords;
		}
	}
	
	cout<<nrLetters<< '\n';
	cout<<nrWords<<'\n';
	
	averageLength = nrLetters/nrWords;
	fout<<averageLength;
	
	return 0;
}