ACM题目大都有规定运行时间的, /O+e#z2f<
=[ APMig,n
那么我们如何测得程序运行时间呢? 'aNahzb
]S*E
这就得益于C++函数库time.h "i}Z(_7yr
t
]71
下面是一段示范代码: [9w, WJL
<
rv1IJ
#include<iostream> j\nE8WH
#include<time.h> Q.*'H_Y
using namespace std; V2lp7"
int main() Y7*'QKz2
{ 9&&kgKKGQ
long beginTime =clock();//获得开始时间,单位为毫秒 m)(SG
W6)dUi
:"
for(int i=0;i<10000;i++){cout<<i<<endl;}//输出10000行数字 C5BzWgK
G#^m<G^M
long endTime=clock();//获得结束时间 anpJAB:1
_T_PX$B
cout<<"beginTime:"<<beginTime<<endl )H.ubM1
<<"endTime:"<<endTime<<endl [f/vLLK
<<"endTime-beginTime:"<<endTime-beginTime<<endl; .QNjeMu.
}k4`
return 0; ,>:XE@xcp
}