Pagini recente » Cod sursa (job #463011) | Cod sursa (job #1028157) | Cod sursa (job #2069676) | Cod sursa (job #210431) | Cod sursa (job #479429)
Cod sursa(job #479429)
// 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;
}