Cod sursa(job #2810829)

Utilizator indianu_talpa_iuteTisca Catalin indianu_talpa_iute Data 30 noiembrie 2021 12:57:31
Problema Text Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <bits/stdc++.h>
#define MAX_SZ 1000000

using namespace std;

ofstream fout("text.out");

bool esteAlfabet(char n)
{
    return (n >= 'a' && n <= 'z') || (n >= 'A' && n <= 'Z');
}

int main()
{
    FILE *input = fopen("text.in", "r"), *output = fopen("text.out", "w");
    int sz, litere = 0, cuvinte = 0;
    char text[MAX_SZ];

    //citirea
    fseek(input, 0L, SEEK_END);
    sz = (int)ftell(input);
    rewind(input);
    fread(text, sizeof(char), sz, input);

    for (int i = 0; i < sz; i++)
    {
	while (!esteAlfabet(text[i]))
	    i++;

	cuvinte++;
	while (esteAlfabet(text[i]))
	{
	    litere++;
	    i++;
	}
    }

    fprintf(output, "%d", litere / cuvinte);
    return 0;
}