#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>

struct elem{
char st[80];
elem *next;
elem *pred;
};
void printfl(elem *first)
{ elem *cur;
puts("inputed spisok first -> last");
cur=first;
while(cur!=NULL)
{puts(cur->st);
cur=cur->next;}
printf("\n");
}
void printlf(elem * last)
{elem * cur;
cur=last;
puts("inputed spisok last -> first");
while(cur!=NULL)
{puts(cur->st);
cur=cur->pred;}
printf("\n");
}

int kolslov(char *s)
{int i;
int kols=0;
for(i=0;i<=strlen(s);i++)
if ((s[i]==' ')||(s[i]=='\0'))
kols=kols+1;
return kols;
}
void main()
{elem *first, *cur, *tmp, *last;
char snum[80];
int n,k;
puts("Input string or ENTER");
first=new elem;
gets(snum);
strcpy(first->st,snum);
first->next=NULL;
first->pred=NULL;
last=first;
while(gets(snum),strlen(snum)!=0)
{cur=new elem;
strcpy(cur->st,snum);
cur->next=NULL;
cur->pred=last;
last->next=cur;
last=cur;
}
printfl(first);
printlf(last);

puts("String with kolslov <3 ");
while((first!=NULL)&&(kolslov(first->st)<3))
{ cur=first;
puts(cur->st);
first=first->next;
first->pred=NULL;
delete cur;
}
if(first!=NULL)
{ cur=first;
while(cur!=NULL)
{
if(kolslov(cur->st)<3)
{ puts(cur->st);
tmp=cur;
tmp->pred->next=cur->next;
if(cur->next!=NULL)
cur->next->pred=cur->pred;
else
last=cur->pred;
cur=cur->next;
delete tmp;
}
else
cur=cur->next;
}
printfl(first);
printlf(last);
}
else puts("Spisok is empty");

puts("Delete spisok");
while(first!=NULL)
{ cur=first;
first=first->next;
delete cur;
}
cur=last=tmp=NULL;
getch();

}