Pagini recente » Cod sursa (job #2409721) | Cod sursa (job #371218) | Cod sursa (job #1699374) | Cod sursa (job #841740) | Cod sursa (job #609615)
Cod sursa(job #609615)
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
ifstream f;
ofstream g;
int nrLetters, nrWords;
string str;
nrLetters = 0;
nrWords = 0;
f.open("text.in");
g.open("text.out");
getline(f, str);
if (str.size() != 0)
{
for (int i=0; i<str.size();i++)
{
if (isalpha(str[i])) nrLetters++;
else if (isalpha(str[i-1])) nrWords++;
}
if (isalpha(str[str.size()-1])) nrWords++;
if (nrWords != 0)
g << nrLetters/nrWords;
else g<<"0";
}
else g <<"0";
return 0;
}