Cod sursa(job #2718031)

Utilizator darkeagleDaniel Popescu darkeagle Data 8 martie 2021 13:03:25
Problema Text Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <bits/stdc++.h>
using namespace std;
#define OUT 0
#define IN 1

unsigned countWords(char *str)
{
    int state = OUT;
    unsigned wc = 0;
    while(*str)
    {
        if(*str == ' ' || *str == '\n' || *str == '\t')
            state = OUT;
        else if(state == OUT)
        {
            state  = IN;
            ++wc;
        }
        ++str;
    }
    return wc;
}

int main()
{

    freopen("text.in", "r", stdin);
    freopen("text.out", "w", stdout);

    char text[100000];

 cin.getline(text, 100000);
int nr =0;

for(int i = 0; i < strlen(text); i++)
{if((text[i] >= 'a' && text[i] <= 'z') || (text[i] >= 'A' && text[i] <= 'Z'))
        nr++;
}

cout << nr/countWords(text) << endl;

    return 0;
}