Pagini recente » Cod sursa (job #786623) | Istoria paginii runda/baraj2017/clasament | Cod sursa (job #1594790) | Cod sursa (job #2318957) | Cod sursa (job #1334385)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max 10000
int calc(char* s);
int main()
{
FILE* in = fopen("text.in","r");
FILE* out = fopen("text.out","w");
char *s = (char*)malloc(sizeof(char)*max);
fgets(s,max,in);
printf("%s",s);
int c = calc(s);
fprintf(out,"%d",c);
return 0;
}
int calc(char* s){
int nrWords=0;
int length = 0;
char * tok = strtok(s," `~1234567890!{@#$%^&**()-}|\":+?=><,./;'[]\"");
while(tok!=NULL){
length += strlen(tok);
nrWords++;
tok=strtok(NULL, " `~1234567890!{@#$%^&**()-}|\":+?=><,./;'[]\"");
}
return length/nrWords;
}