分解质因数(高级版)

分解质因数

分解质因数可谓是在奥数里躲不开的一关,同时,通过分解质因数也会使你发现许多有趣的数。可是有些人可能不会分解质因数,今天我就给你写一个小程序

记得加关注呦

下面是代码:
头文件

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include <iomanip>
#include <windows.h>

使用空间:

 
using namespace std;

准备阶段:

void gotoxy(int x, int y)
{
	COORD pos = {x,y}; 
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);  
	SetConsoleCursorPosition(hOut, pos);
} 
 
void hidden()
{
    	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    	CONSOLE_CURSOR_INFO cci;
	GetConsoleCursorInfo(hOut,&cci);
	cci.bVisible=0;
	SetConsoleCursorInfo(hOut,&cci);
}
 
class Timer
{
	private:
		long start_time;
		long pause_time;
		 
		bool is_pause; 
		bool is_stop;
	public:
		Timer();
		bool isPause();  
		bool isStop();
		
		void Start(); 
		void Pause();
		void Stop();
		inline long getStartTime() {return start_time;}
		void show();
};
 
Timer::Timer()
{
	is_pause = false; 
	is_stop = true;
}
 
 
bool Timer::isPause()
{	
	if(is_pause)
	return true;
	else
	return false;
}
 
bool Timer::isStop()
{
	if(is_stop)
		return true;
	return false;
} 
 
void Timer::Start()  
{
	if(is_stop)
	{
		start_time = time(0);
		is_stop = false;
	}
	else if(is_pause)
	{
		is_pause = false;
		start_time += time(0)-pause_time; 
	}
}
 
void Timer::Pause() 
{
	if(is_stop||is_pause) 
		return; 
	else   
	{
		is_pause = true;
		pause_time = time(0);  
	}
}
void Timer::Stop()   
{
	if(is_stop) 
		return ; 
	else if(is_pause)  
	{
		is_pause = false;
		is_stop = true;
	}
	else if(!is_stop)
	{
		is_stop = true;
	} 
}
 
void Timer::show()
{
	long t = time(0) - start_time;
	gotoxy(35,12);
	cout<<setw(2)<<setfill('0')<<t/60/60<<":"
	    <<setw(2)<<setfill('0')<<t/60<<":"
		<<setw(2)<<setfill('0')<<t%60<<endl;
}

主函数:

int main()
{
	Timer t; 
	char ch; 
	hidden();//隐藏光标
	system("color 02"); 
	gotoxy(35,12);
	cout<<"00:00:00";
	gotoxy(20,18);
	cout<<"按a开始,按空格暂停,按s停止";
	while(1)
	{
		if(kbhit())
		{
			ch = getch();
			switch (ch)
			{
				case 'a':t.Start();break;
				case 's':t.Stop();break;
				case ' ':t.Pause();break;
				default :break;
			}
		}
		if(!t.isStop()&&!t.isPause()) 
		{
			t.show();
		}
	}
	
}

下面是完整代码:

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include <iomanip>
#include <windows.h>
 
using namespace std;
void gotoxy(int x, int y)
{
	COORD pos = {x,y}; 
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);  
	SetConsoleCursorPosition(hOut, pos);
} 
 
void hidden()
{
    	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    	CONSOLE_CURSOR_INFO cci;
	GetConsoleCursorInfo(hOut,&cci);
	cci.bVisible=0;
	SetConsoleCursorInfo(hOut,&cci);
}
 
class Timer
{
	private:
		long start_time;
		long pause_time;
		 
		bool is_pause; 
		bool is_stop;
	public:
		Timer();
		bool isPause();  
		bool isStop();
		
		void Start(); 
		void Pause();
		void Stop();
		inline long getStartTime() {return start_time;}
		void show();
};
 
Timer::Timer()
{
	is_pause = false; 
	is_stop = true;
}
 
 
bool Timer::isPause()
{	
	if(is_pause)
	return true;
	else
	return false;
}
 
bool Timer::isStop()
{
	if(is_stop)
		return true;
	return false;
} 
 
void Timer::Start()  
{
	if(is_stop)
	{
		start_time = time(0);
		is_stop = false;
	}
	else if(is_pause)
	{
		is_pause = false;
		start_time += time(0)-pause_time; 
	}
}
 
void Timer::Pause() 
{
	if(is_stop||is_pause) 
		return; 
	else   
	{
		is_pause = true;
		pause_time = time(0);  
	}
}
void Timer::Stop()   
{
	if(is_stop) 
		return ; 
	else if(is_pause)  
	{
		is_pause = false;
		is_stop = true;
	}
	else if(!is_stop)
	{
		is_stop = true;
	} 
}
 
void Timer::show()
{
	long t = time(0) - start_time;
	gotoxy(35,12);
	cout<<setw(2)<<setfill('0')<<t/60/60<<":"
	    <<setw(2)<<setfill('0')<<t/60<<":"
		<<setw(2)<<setfill('0')<<t%60<<endl;
}
 
int main()
{
	Timer t; 
	char ch; 
	hidden();//隐藏光标
	system("color 02"); 
	gotoxy(35,12);
	cout<<"00:00:00";
	gotoxy(20,18);
	cout<<"按a开始,按空格暂停,按s停止";
	while(1)
	{
		if(kbhit())
		{
			ch = getch();
			switch (ch)
			{
				case 'a':t.Start();break;
				case 's':t.Stop();break;
				case ' ':t.Pause();break;
				default :break;
			}
		}
		if(!t.isStop()&&!t.isPause()) 
		{
			t.show();
		}
	}
	
}

本文为转载文章

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值