Cod sursa(job #783642)

Utilizator SeekHunt1334Septimiu Bodica SeekHunt1334 Data 3 septembrie 2012 15:06:33
Problema Text Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include <iostream>
#include <cstdio>
#include <fstream>
using namespace std;

ifstream fin("text.in");
ofstream fout("text.out");

bool CharCheck(char character);

int nrc = 1, nrtl = 0;

int main()
{
    int thischar = fin.get();

    while (thischar != '\n')
    {

        if ( CharCheck(thischar) )
            nrtl++;
        else
        if ( thischar == ' ' || thischar == '-')
            nrc++;

        thischar = fin.get();
    }

    cout << nrtl << ' ' << nrc << '\n';
    cout << nrtl/nrc << '\n';

    return 0;
}

bool CharCheck(char character)
{
    static bool firstword = false;
    if (firstword == false)
        if ( character == ' ' || character == '-' )
        {
            nrc --;
        }

    if ( (int)character >= 97 && (int)character <= 122 )
    {
        firstword = true;
        return true;
    }
    if ( (int)character >= 65 && (int)character <= 90 )
    {
        firstword = true;
        return true;
    }
    return false;
}