Pagini recente » Cod sursa (job #1005368) | Cod sursa (job #1739284) | Cod sursa (job #2101369) | Cod sursa (job #1403700) | Cod sursa (job #1051835)
//
// 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;
}