#include <bits/stdc++.h>
#include <winsock2.h>
#include <windows.h>
#include <windowsx.h>
#include <cstring>
#include <time.h>
#include <string>
#include <chrono>
#include <cinttypes>
#include <ctime>
#include <sstream>
#include <iomanip>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
int month, day, hour, minute, second;
string year;
cout<<" 欢迎使用定时关机程序! "<<endl;
cout<<endl;
cout<<" 作者:陶** "<<endl;
cout<<endl;
cout<<" Powerd By LTC"<<endl;
cout<<endl;
cout<<" Welcome! "<<endl;
cout<<endl;
cout<<endl;
cout<<"请输入5个整数,分别是年、月、日、小时、分钟(如果要让程序正常关机,请不要关闭改exe文件)"<<endl;
cout<<"如果想要取消该进程,请在规定时间前运行一个程序,如果想显示此程序源码,输入code(不要大写)"<<endl;
cout<<"如果想要立刻关机,输入now(不要大写)"<<endl;
cout<<"如果不需要,按第一行输入即可"<<endl;
cout<<"请输入二十四时计时法的时间!!!"<<endl;
time_t now = time(0);
tm *ltm = localtime(&now);
cout<<"现在时间: "<<1900+ltm->tm_year<<"-"<<1+ltm->tm_mon<<"-"<<ltm->tm_mday<<" ";
cout<<ltm->tm_hour<<":"<<ltm->tm_min<<":"<<ltm->tm_sec<<endl;
while(cin>>year)
{
if(year=="code")
{
string ss=" system(shutdown -a);";
ss.insert(ss.begin()+16, '"');
ss.insert(ss.begin()+28, '"');
cout<<"#include <bits/stdc++.h>"<<endl;
cout<<"#include <windows.h>"<<endl;
cout<<"using namespace std;"<<endl;
cout<<"int main()"<<endl;
cout<<"{"<<endl;
cout<<" ios::sync_with_stdio(0);"<<endl;
cout<<" while(true)"<<endl;
cout<<" {"<<endl;
cout<<ss<<endl;
cout<<" }"<<endl;
cout<<" return 0;"<<endl;
cout<<"}"<<endl;
continue;
}
else if(year=="now")
{
system("shutdown -p");
return 0;
}
else
{
int yy;
stringstream ss;
ss<<year;
ss>>yy;
cin>>month>>day>>hour>>minute>>second;
time_t now = time(0);
tm *ltm = localtime(&now);
cout<<"现在时间: "<<1900+ltm->tm_year<<"-"<<1+ltm->tm_mon<<"-"<<ltm->tm_mday<<" ";
cout<<ltm->tm_hour<<":"<<ltm->tm_min<<":"<<ltm->tm_sec<<endl;
cout<<"关机种子已经埋下!";
while(true)
{
time_t now = time(0);
tm *ltm = localtime(&now);
if(1900+ltm->tm_year==yy && month==1+ltm->tm_mon && ltm->tm_mday==day && ltm->tm_hour==hour
&& ltm->tm_min==minute && ltm->tm_sec==second)
{
system("shutdown -p");
return 0;
}
Sleep(1000);
}
return 0;
}
}
return 0;
}
C++定时关机程序
最新推荐文章于 2024-07-16 19:38:19 发布