Cod sursa(job #1300341)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 24 decembrie 2014 12:49:45
Problema Text Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <fstream>
using std::ifstream;
using std::ofstream;

#include <vector>
using std::vector;

#include <iterator>
using std::istream_iterator;
using std::back_inserter;

#include <cstdlib>
//isalpha

#include <iostream>
using std::cout;

void citeste_cuvinte(ifstream& f, int& suma, int& nr_cuvinte){
	char trecut = 0, curent = 0;
	// asta-i importanta !!!!!
	f >> std::noskipws;
	// am pierdut o ora din cauza lui std::noskipws!!!!!
	f >> curent;
	if(isalpha(curent)){
		++nr_cuvinte; }
	while(trecut = curent, f >> curent){
		if(isalpha(trecut) && !isalpha(curent)){
			++nr_cuvinte; }
		if(isalpha(trecut)){
			++suma; } } }
		
int main(){
	std::ios_base::sync_with_stdio;
	ifstream f("text.in");
	ofstream g("text.out");
	int suma = 0, nr_cuvinte = 0;
	citeste_cuvinte(f, suma, nr_cuvinte);
	g << suma / nr_cuvinte;
	return 0; }