Cod sursa(job #2609286)

Utilizator bogdanili123Iliescu Bogdan bogdanili123 Data 2 mai 2020 13:19:57
Problema Text Scor 60
Compilator cpp-64 Status done
Runda igorj_mentorat1 Marime 1.45 kb
#include <fstream>
#include <iostream>
#include <cstring>
using namespace std;
ifstream f ("text.in");
ofstream g ("text.out");
char s[100001],t[100001],t1[100001], *pi,h;

int i,p,x,ok,ok1,k,suma,medie,ky;
int main()
{
    while (f.get(h))
    {

       if ((h >= 'a' && h <= 'z') || (h >= 'A' && h <= 'Z') || h==' ')
          {
            s[ky]=h;
            ky++;
            }
        else
            if (h=='-')
                {
                  s[ky]=' ';
                   ky++;
                }
    }
   // g<<s;
   // return 0;
    ok=1;
    for(i=0; i<strlen(s) && ok==1; i++)
    {
        if(s[i]==' ')
            p++;
        else
            ok=0;

    }
    strcpy(t,s+p);
    strcpy(s,t);
    p=0;
  /*  for(i=1; i<strlen(s); i++)
    {
        if(s[i]==' ' && s[i+1]==' ')
        {
            strcpy(t,s+i+1);
            strcpy(s+i,t);
            i--;
        }
    }
    if(s[strlen(s)-1]==' ')
        strcpy(s+strlen(s)-1,s+strlen(s));
    */
    ok1=1;
    p=0;
    for(i=0; i<strlen(s) && ok1==1; i++)
    {
        if(s[i]==' ')
            p++;
        else
            ok1=0;

    }
    strcpy(t1,s+p);
    strcpy(s,t1);
    if (strlen(s)!=0)
    {

     pi=strtok (s," ");
      while (pi)
      {
          k++;
          suma=suma+strlen(pi);
          pi=strtok (NULL," ");
      }
      medie=suma/k;
        g<<medie;
    }
    else
       g<<0;
    return 0;

}