写一份蒟蒻的倒计时程序 (美化极不到位)
#include <iostream>
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define scta(a) SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE),a);
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLK_TCK ;
while (clock() < endwait) {}
}
int main() {
time_t rawtime;
struct tm * target_time;
int d,h,m,s;
int k=0;
long double dif,r;
time_t now,t_end;
time ( &rawtime );
target_time = localtime ( &rawtime );
target_time->tm_year = 2024 - 1900;
target_time->tm_mon= 7 - 1;
target_time->tm_mday = 27 ;
target_time->tm_hour = 1 ;
target_time->tm_min = 30 ;
target_time->tm_sec = 0 ;
t_end = mktime (target_time);
while (k < 200){
now = time (NULL);
dif = difftime (t_end,now);
d = (int) (dif / 86400.0);
r = dif - d * 86400.0;
h = (int) (r / 3600.0);
r = r - h * 3600.0;
m = (int) (r / 60.0);
r = r - m * 60.0;
s = (int) (r);
scta(6);
printf("距离2024年巴黎奥运会还有\n");
printf(" %d天%d小时%d分%d秒(北京时间)\n",d,h,m,s);
scta(6);
printf("\n\n");
if(d<2)printf("There is still %d day %d hour %d minute %d second (UTC+8) left until the 2024 Paris Olympics",d,h,m,s) ;
else printf("There are still %d day %d hour %d minute %d second (UTC+8) left until the 2024 Paris Olympics",d,h,m,s) ;
(void) wait ( 1 );
k = k + 1;
system("CLS");
};
}