Pagini recente » Cod sursa (job #2776527) | Cod sursa (job #2636315) | Cod sursa (job #609859) | Cod sursa (job #428106) | Cod sursa (job #479642)
Cod sursa(job #479642)
// Afla lungimea medie a cuvintelor din text
#include <fstream>
#include <cstdio>
#include <cstdlib>
using namespace std;
const int MAXSIZE = 1024;
int main() {
ifstream fin("text.in");
ofstream fout("text.out");
char* alfabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
char* buffer = new char[MAXSIZE];
int nr_w=0, nr_l=0;
while (!fin.eof()) {
fin >> buffer;
for(int i=0; i<(int)strlen(buffer) ; i++) {
if (strchr(alfabet,buffer[i])==NULL) {
i++;
while ((strchr(alfabet,buffer[i])==NULL)&&(i<=(int)strlen(buffer)))
i++;
if (i<(int)strlen(buffer)) {
nr_w+=1;
nr_l+=1;
}
}
else {
if (i==0) {
nr_w++;
}
nr_l+=1;
}
}
}
fout << nr_l/nr_w;
fin.close();
fout.close();
return 0;
}