Cod sursa(job #1349167)

Utilizator andy94Andrei Ursache andy94 Data 20 februarie 2015 00:15:13
Problema Text Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
//============================================================================
// Name        : Text.cpp
// Author      : Andrei
// Version     :
// Copyright   : Your copyright notice
// Description : Text - InfoArena
//============================================================================

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {

	FILE *in = fopen("text.in", "r");
	FILE *out = fopen("text.out", "w");

	int w=0;
	int l=0;

	char data[512];
	char delim[] = " ,.?!-_}{[]\\|/:;\'\"";
	char *p;
	while (!feof(in)) {
		fread(data, 1, 512, in);
		p = strtok(data, delim);
		while(p!=NULL){
			w++;
			l+=strlen(p);
			p = strtok(NULL,delim);
		}

	}

	int r = l/w;
	char result[3];
	sprintf(result,"%d",r);
	fputs(result,out);

	fclose(in);
	fclose(out);

	return 0;
}