Cod sursa(job #834788)

Utilizator gabrielinelusGabriel-Robert Inelus gabrielinelus Data 15 decembrie 2012 11:58:17
Problema Text Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
char text[20000];
int main()
{
    int i;
    FILE *f=fopen("text.in","r");
    fgets(text,20000,f);
    if(text[strlen(text)-1]=='\n')
    text[strlen(text)-1]=0;
    int nrchr=0;
    for(i=0;i<=strlen(text)-1;i++)
    if(!isalpha(text[i]))
    text[i]=' ';
    else
    nrchr++;
    if(text[0]==' ')
    while(text[0]==' ')
    strcpy(text,text+1);
    char *p;
    p=text;
    int ncuv=0;
    for(p=strtok(text," ");p;p=strtok(NULL," "))
    ncuv++;
    fclose(f);
    f=fopen("text.out","w");
    fprintf(f,"%d",nrchr/ncuv);
    return 0;
}