#include <stdio.h>
#include <conio.h>
#include <time.h>

#define STATE_RUN  0
#define STATE_WAIT 1
#define STATE_QUIT 2


int main(){
	time_t now,last;
	int c;
	int state=STATE_RUN;
	
	last=time(NULL);
	do{
		if(kbhit()){
			c=getch();
			switch(c){
			case 'q':
				state=STATE_QUIT;
				break;
			case 'p':
				if(state==STATE_RUN){
					state=STATE_WAIT;
				}else{
					state=STATE_RUN;
				}
			}
		}
		
		switch(state){
		case STATE_RUN:
			now=time(NULL);
			if(last-now!=0){
				last=now;
				printf("a");
				fflush(stdout);
			}
		}
	}while(state!=STATE_QUIT);
	
	return 0;
}
