Cod sursa(job #29943)

Utilizator reSpawnPopescu Ioan reSpawn Data 11 martie 2007 20:27:44
Problema Text Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <string.h>
#include <fstream.h>
using namespace std;
int main()
{
    char text[1048576];
    ifstream read("text.in");
    ofstream write("text.out");
    read.getline(text, 1048578);
    unsigned int length = strlen(text);
    unsigned int i, litere = 0, cuvinte = 2;
    for(i = 0; i < length; ++i)
          if (isalpha(text[i]))
          litere++;
          else if(i>=1 && text[i] == ' ' && isgraph(text[i-1]) && isgraph(text[i+1]))
          cuvinte++;
          else if(i>=1 && text[i] == '-' && isgraph(text[i-1]) && isgraph(text[i+1]))
          cuvinte++;
          else if(text[i] == '-' && isgraph(text[i+1]))
          cuvinte++;
    write << litere / cuvinte;
    return 0;   
}