// spudal onkr3.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>

struct elem{
	int num;
	elem *next;
	};
	elem *first, *cur, *tmp,*q, *last;
	char snum[10];

 void main()
 {
	 int n,k;
	 puts("Input integer value or ENTER");
  first=new elem;
  puts("");
  gets(snum);
  first->num=atoi(snum);
  first->next=NULL;
  last=first;
   while(gets(snum),strlen(snum)!=0)
   {cur=new elem;
    cur->num=atoi(snum);
	cur->next=NULL;
	if(cur->num<0)
	{last->next=cur;
	last=cur;
     }
	else
	{cur->next=first;
	first=cur;
	}
   }
  puts("inputed spisok first -> last");
  cur=first;
  while(cur!=NULL)
  {printf("%5d",cur->num);
  cur=cur->next;}
  printf("\n");
  k=0;
  cur=first;tmp=first;
  puts("\nDelete elements");
  while(cur!=NULL)
  { 
	  k++;
    if (k%3==0)
     { printf("%5d",cur->num);
		 if (cur->next!=NULL)
		{ q=cur;
	      tmp->next=cur->next;
		  cur=cur->next;
		  delete q;
		}
		else 
		{
			tmp->next=NULL;
		    last=tmp;
			delete cur;
			cur=tmp->next;
		 }
	    
       }
	else { tmp=cur;cur=cur->next;}
  }
puts("\n\ninputed spisok first -> last after del every  3");
  cur=first;
  while(cur!=NULL)
  {printf("%5d",cur->num);
  cur=cur->next;}
  printf("\n");
   
  getch();

}
