Cod sursa(job #1051835)

Utilizator kommancs96Nagy Daniel kommancs96 Data 10 decembrie 2013 17:04:47
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
//
//  main.cpp
//  Text
//
//  Created by Nagy Dani on 2013.12.10..
//  Copyright (c) 2013 Nagy Dani. All rights reserved.
//
#include <cstdio>
#include <cstdlib>
#include <vector>
std::vector<long long> words;

inline int is_char(int c){
    return ( (c >= 65 && c<= 90) || (c >= 97 && c<= 122) ) ? 1 : 0;
}

void calculate(){
    FILE* in = fopen("text.in", "r");
    int bint = 0,c;
    do {
        c = fgetc(in);
        bint = is_char(c);
        if (bint) {
            long long letterCount = 0;
            while (is_char(c)) {
                c = fgetc(in);
                letterCount ++;
            }
            words.push_back(letterCount);
        }
    } while (c != EOF);
}
void print_average(){
    FILE* out = fopen("text.out", "w");
    long long n = 0;
    unsigned long long sum = 0;
    std::vector<long long>::iterator it = words.begin();
    for (; it != words.end(); ++it) {
        n++;
        sum += (*it);
    }
    
    unsigned long long av = sum/n;
    fprintf(out, "%llu",av);
}
int main(int argc, const char * argv[])
{
    calculate();
    print_average();
    return 0;
}