📄 421a.cpp
字号:
//421a.cpp using class FTimer
#include "FTimer.H"
const unsigned long MAXNUM = 1000000L; //1M
main(void)
{
FTimer t0,t1,t2;
unsigned long TestNum, Current;
//project 0
t0.Start();
for(TestNum = 3; TestNum<MAXNUM; TestNum++)
{
Current=TestNum;
do
{
if(Current%2)
Current = 3*Current+1;
else
Current /= 2;
}while(Current!=1);
}
t0.Stop();
cout << "The Project0 total time = " ;
t0.DisplayDeltaTime();
//project 1
t1.Start();
for(TestNum = 3; TestNum<MAXNUM; TestNum+=2)
{
Current=TestNum;
do
{
if(Current%2)
Current = 3*Current+1;
else
Current /= 2;
}while(Current > TestNum);
}
t1.Stop();
cout << "The Project1 total time = " ;
t1.DisplayDeltaTime();
//project 2
t2.Start();
for(TestNum = 3; TestNum<MAXNUM; TestNum+=2)
{
Current=TestNum;
do
{
if(Current%2)
Current = Current++ + (Current>>1) ;
else
Current /= 2;
}while(Current > TestNum);
}
t2.Stop();
cout << "The Project2 total time = " ;
t2.DisplayDeltaTime();
return(0);
}
/*
The Project0 total time = 6980mS
The Project1 total time = 220mS
The Project2 total time = 110mS
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -