额,经过很长时间的改正,但计时还是不太准,不过误差不大:
#include <bits/stdc++.h>
using namespace std;
int main(){
long long a = 0,i = 0;
float secs;
cin>>secs;
cout<<"计时开始"<<endl;
clock_t delay;
delay=secs * CLOCKS_PER_SEC;
clock_t start=clock();
while(clock()-start < delay){
i++;
if(i >=140000000){
a++;
if(a > secs){
break;
}
i = 0;
cout<<"过了"<<a<<"秒"<<endl;
}
};
cout<<"计时结束"<<endl;
return 0;
}