Pagini recente » Cod sursa (job #3242267) | Rating chiar nu cont (eaza) | Cod sursa (job #949808) | Cod sursa (job #3226537) | Cod sursa (job #2269348)
#include <iostream>
#include <fstream>
using namespace std;
inline bool elitera(char c)
{
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}
int main()
{
ifstream ii("text.in");
ofstream oo("text.out");
string str;
int nrCuv = 0, nrLit = 0;
while (getline(ii, str))
{
const char* buf = str.c_str();
bool last = false;
int n = str.length();
for (int i = 0; i < n; i++)
{
if (elitera(buf[i]))
{
if (!last)
nrCuv++;
nrLit++;
last = true;
}
else
last = false;
}
}
cout << "Numar de cuvinte : " << nrCuv << "\nNumar de litere : " << nrLit;
if (nrCuv == 0)
oo << 0;
else
oo << nrLit / nrCuv;
ii.close(); oo.close();
}