Cod sursa(job #1043040)

Utilizator GrandmasterSoucup Bogdan Grandmaster Data 27 noiembrie 2013 22:06:50
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include<iostream>
#include<cstring>
#include<fstream>
#include <cstdio>
using namespace std;
int const MAX = 1024 * 1024 + 7;
char s[MAX];
char *sneaky = s + 1;
int WordCount(char s[])
{
	int i = 0, k, Contor = 0;
	k = strlen(s);
	while (i < k)
	{
		if (isalpha(s[i]) == 0 && isalpha(s[i + 1]) != 0)
			Contor++;
		i++;
	}
	return Contor;
}
int main()
{
	int i, sr, k = 0, z = 1;
	ofstream f("text.out");

	FILE *g = fopen("text.in", "r");

	char currentChar;
	int idx = 0;

	while (fscanf(g, "%c", &currentChar) != EOF) {
		sneaky[idx++] = currentChar;
	}
	
	sneaky[idx] = 0;

	s[0] = ' ';
	sr = strlen(sneaky);
	for (i = 0; i < sr; i++)
	{
		if (isalpha(sneaky[i]))
			k++;
	}

	f << k / WordCount(s);
}