#include int get_input_type(char c)
{
if(c == ' ')
return 1;
return 0;
}
int main(void)
{
char buf[] = " This is a book. That is a bag\n";
//input 11000010011101000001111000011001010000
//state 012000010012201000001222000012001010000
//print p pppppppp pppppppp ppppp ppppppppp
//0 0 -> 0
//0 1 -> 1
//1 0 -> 0
//1 1 -> 2
//2 0 -> 0
//2 1 -> 2
int state = 0;
int i = 0;
char *p;
int counter = 0;
printf("buf = %s\n",buf);
i = 0;
while(1)
{
char c;
int input = 0;
c = buf[i];
input = get_input_type(c);
//printf("c = %c,input = %d\n",c,input);
if(c == '\0')
break;
//0 0 -> 0
//0 1 -> 1
//1 0 -> 0
//1 1 -> 2
//2 0 -> 0
//2 1 -> 2
if(state == 0 && input == 0)
{
state = 0;
printf("%c",c);
}
else
if(state == 0 && input == 1)
{
state = 1;
printf("%c",c);
}
else
if(state == 1 && input == 0)
{
state = 0;
printf("%c",c);
}
else
if(state == 1 && input == 1)
{
state = 2;
//do nothing ,dont output
}
if(state == 2 && input == 0)
{
state = 0;
printf("%c",c);
}
else
if(state == 2 && input == 1)
{
state = 2;
//do nothing ,dont output
}
i++;
}
return 0;
}