Pagini recente » Statistici Obreja Ionela Loredana (obrejaionela) | Cod sursa (job #3270615) | Cod sursa (job #2352807) | Cod sursa (job #908234) | Cod sursa (job #479646)
Cod sursa(job #479646)
// 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];
bool flag;
int nr_w=0, nr_l=0;
while (!fin.eof()) {
flag = false;
fin >> buffer;
for(int i=0; i<(int)strlen(buffer); i++) {
if (strchr(alfabet,buffer[i])==NULL) {
flag = false;
}
else {
if (flag==false) {
nr_w++;
flag = true;
}
nr_l+=1;
}
}
}
fout << nr_l/nr_w;
fin.close();
fout.close();
return 0;
}