Cod sursa(job #2203533)

Utilizator AndrulianDin Iulian Andrulian Data 12 mai 2018 17:07:28
Problema Text Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <bits/stdc++.h>

using namespace std;
char c[1200];
char sep[]=". , - ; ! ?>= ";
int n,lungime,cuvinte,i;
ifstream fin("text.in");
ofstream fout("text.out");
int litera(char c)
{
    if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
        return 1;
}
int main()
{
    fin.get(c,1200);
    //  cout<<c;
    char *p=strtok(c,sep);
    char s[150];
    while(p!=NULL)
    {
        // cout<<p<<endl;
        n=strlen(p);
        strcpy(s,p);
        //  cout<<s<<" ";
        bool ok=1;
        for(i=1; i<=n&&ok==1; i++)
        {
            if(litera(s[i])==1)ok=1;
            else ok=0;
        }
        if(ok=1)
        {
            cuvinte++;
            lungime=lungime+n;
            //cout<<cuvinte<<" "<<lungime<<"\n";
        }

        p=strtok(NULL,sep);
    }
    // fout<<cuvinte<<" "<<lungime<<"\n";
    if(cuvinte==0)fout<<0;
    else
        fout<<lungime/cuvinte;
    return 0;
}