跳到正文

学习·文化课

上课计时器

tttyyygdgz约 3 分钟
原文
文章信息与版本

文章信息

收录
2026年5月30日
更新
2026年7月1日
篇幅
约 3 分钟

版本

  1. v1当前

需打开 -std=c++11 编译选项

设定的时间:12:00-13:00(EZOI中午集训)

C++
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#define go(x,y) SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),{(x),(y)});
using namespace std;
bool flag;
int l_m,l_s; 
tm *t;
time_t tt;
void daka(){
	while(!getch());
	if(t->tm_hour==13){
		l_m=t->tm_min;
		l_s=t->tm_sec;
	}
	flag=1;
	return;
}
int main(){
	system("mode con lines=8 cols=36");
    thread t1(daka);
    t1.detach();
    CONSOLE_CURSOR_INFO cci={1,0};
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cci);
	while(1){
		time(&tt);
		t=localtime(&tt);
		printf("现在的时间:%4d年%02d月%02d日 %02d:%02d:%02d\n\n",t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
		if(t->tm_hour<13){
			if(13-t->tm_hour>1){
				printf("距离上课还有%02d时%02d分%02d秒\n\n",15-t->tm_hour,59-t->tm_min,60-t->tm_sec);
			}
			else{
				printf("距离上课还有%02d分%02d秒    \n\n",59-t->tm_min,60-t->tm_sec);
			}
			printf("%s",(flag?"已打卡      ":"按任意键打卡"));
			
		}
		else if(t->tm_hour<14){
			if(flag){
				printf("距离下课还有%02d分%02d秒\n\n",59-t->tm_min,60-t->tm_sec);
				if(l_m==0)printf("你今天没迟到\n\n");
				else printf("你今天迟到了%02d分%02d秒\n\n",l_m,l_s);
				printf("已打卡");
			}
			else{
				printf("你已经迟到了%02d分%02d秒\n\n",t->tm_min,t->tm_sec);
				printf("按任意键打卡");
			} 
		}
		else{
			printf("%s",(flag?"下课了!            ":"你旷课了!          ")); 
			printf("\n\n            "); 
		}
		go(0,0);
		Sleep(100);
	}
	return 0;
}
原文