Cod sursa(job #52571)

Utilizator BlackElfSpulber Iosif BlackElf Data 19 aprilie 2007 11:52:17
Problema Text Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.07 kb
#include<iostream.h>
#include <fstream.h>
#include <string.h>

fstream in ("text.in",ios::in);
fstream out ("text.out", ios::out);       //Lasa-ma, te rog!
int s=0,n=0;
char word[1000];

int let (char a)
{
 if ( ('a' <= a && a <= 'z') || ('A' <= a && a <= 'Z') )
  return 1;
 return 0;
}

void count ()
{
 int sl,i,ew=1;
 sl = strlen (word);
 for (i=0;i<sl;i++)
 {
 // cout<<word[i]<<' '<<endl;
  if (let (word[i]))
   if (ew)
    {
    ++n;
    //sw = 1;
    ew = 0;
    ++s;
  //  cout<<"ew="<<ew<<' '<<"sw="<<sw<<' '<<"s="<<s<<' '<<"n="<<n<<endl; getch();
    }
   else
    {
    ++s;
   // cout<<"ew="<<ew<<' '<<"sw="<<sw<<' '<<"s="<<s<<' '<<"n="<<n<<endl; getch();
    }
  else
   if (!let (word[i]))
    //if (sw)
    {
    //sw = 0;
    ew = 1;
   // cout<<"ew="<<ew<<' '<<"sw="<<sw<<' '<<"s="<<s<<' '<<"n="<<n<<endl; getch();
    }
 }
}

int main ()
{
 // clrscr();

  while (!in.eof())
  {
   in>>word;
   count ();
   //cout<<word<<' ';
  }

 // cout<<"Ceea ce cautai:"<<s/n;
 out<<s/n;

 // getch();

  return 0;
}