Pagini recente » tema | Cod sursa (job #601135) | Cod sursa (job #1262200) | tema | Cod sursa (job #479653)
Cod sursa(job #479653)
// Afla lungimea medie a cuvintelor din text
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int main() {
FILE* fin = fopen("text.in","r");
FILE* fout = fopen("text.out","w");
char* alfabet = new char[52];
strcpy(alfabet,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
char buffer;
bool flag = false;
int nr_w=0, nr_l=0;
while (fscanf(fin,"%c",&buffer)!=EOF) {
if (strchr(alfabet,buffer)==NULL) {
flag = false;
}
else {
if (flag==false) {
nr_w++;
flag = true;
}
nr_l+=1;
}
}
fprintf(fout, "%d", nr_l/nr_w);
return 0;
}