Pagini recente » Istoria paginii utilizator/mihaipmp | Monitorul de evaluare | Clasament dupa rating | Istoria paginii utilizator/slayzor | Cod sursa (job #2011569)
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <stdint.h>
#include <ctype.h>
typedef unsigned int uint;
int main(void)
{
FILE *in = fopen("text.in", "r");
FILE *out = fopen("text.out", "w");
if(in != NULL && out != NULL)
{
int64_t total_len = 0;
int64_t words = 0;
int64_t current = 0;
char c = 'a';
while(1)
{
c = getc(in);
if(c == EOF || c == -1 || c == '\n')
{
if(current > 0)
{
words++;
}
break;
}
else
{
if(ispunct(c) || c == ' ' || isdigit(c))
{
if(current > 0)
{
words++;
current = 0;
}
}
if(isalpha(c) && c != ' ')
{
total_len++;
current++;
}
}
}
// printf("%lld %lld\n", total_len, words);
fprintf(out, "%lld\n", (int64_t)(total_len / words));
fclose(in);
fclose(out);
}
else
{
printf("Error\n");
}
return 0;
}