#include <iostream>
#include <string.h>

using namespace std;

int main()
{
    char text[256]="Am  plecat    la  mare.",s[]="., !?",*p,*q,text2[256],text3[256];
    int nr=0;
   // cout<<"Textul ";
   // cin.get(text,255);
   // cin.get();
    strcpy(text2,text);
    p=strtok(text,s);
    while(p){
        nr++;
        p=strtok(NULL,s);
    }
    cout<<"contine "<<nr<<" cuvinte"<<endl;
    strcpy(text3,text2);
    p=strtok(text2,s);
    while(p){
        cout<<p<<endl;
        p=strtok(NULL,s);
    }
    q=strchr(text3,' ');
    while(q){
        p=strchr(q+1,' ');
       // cout<<q<<endl;
        if(q+1==p) strcpy(q,p);
        else q=p;
    }

    //cout<<p<<endl;
    cout<<text3;

    return 0;
}
