Cod sursa(job #1064075)

Utilizator G_DavidGherghita David G_David Data 21 decembrie 2013 13:56:53
Problema Text Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main()
{
    int len, i, l = 0, s = 0, n = 0;
    string str;

    ifstream infile;
    infile.open("text.in");
    ofstream outfile;
    outfile.open("text.out");

    getline(infile, str);

    len = str.length();
    for (i = 0; i <= len - 1; i += 1) {
        if (i == len) {
                if (l != 0) {
                    s += l;
                    l = 0;
                    n +=1;
                }
        }
        if (isalpha(str[i])) {
            l += 1;
        }
        else if (!(isalpha(str[i]))) {
            if (l != 0) {
                s += l;
                l = 0;
                n += 1;
            }
        }
    }

    outfile << s / n;

    infile.close();
    outfile.close();

    return 0;
}